diff --git a/cms/cms/cmstoken.md b/cms/cms/cmstoken.md new file mode 100644 index 0000000..735655e --- /dev/null +++ b/cms/cms/cmstoken.md @@ -0,0 +1 @@ +ad31a55be0b5efc2d6d7b5490e8d1a31b1a3a2aecbcf99e8f65bcb44bd0189e2918388b942fb3ac7b35fd470d19d475e556489b773c68756977e452aec1ab83f34876ed76ebadafce31636d5621c66820425d1105d753cdc5452d8f3d503ddbaebf45fc6817c235e1f8eae12d118452951ee0a48691446475f7ffc6a72fd6ffb diff --git a/cms/cms/envprodstrapi.md b/cms/cms/envprodstrapi.md new file mode 100644 index 0000000..131959c --- /dev/null +++ b/cms/cms/envprodstrapi.md @@ -0,0 +1,2 @@ +api token=5af45b836a0bcd065b528963e62b6d5d325117dfbf179cd5123087a17906c911fd67bcb57d92f11e869ebda27339b21aa3a7221d3dbbe79de51ef2f9e2af4dae0befe6528872ca2f68f64656ed45c7dfcacea36fdb55d1d9eb2fd9275454ac7ff8ab9acb1535f62449b3f8bd75c24803a2bd0714c637fd1d0bc819798723d999 + diff --git a/cms/cms/scripts/create-api-token.js b/cms/cms/scripts/create-api-token.js new file mode 100644 index 0000000..8109616 --- /dev/null +++ b/cms/cms/scripts/create-api-token.js @@ -0,0 +1,38 @@ +/** + * Script to create an API token for backend integration + * Run this inside the CMS container if the UI doesn't work + */ + +import { factories } from '@strapi/strapi'; + +async function createApiToken() { + const strapi = await factories.createCoreStore()(); + + try { + // Create API token + const tokenService = strapi.service('admin::api-token'); + + const token = await tokenService.create({ + name: 'Backend Integration', + description: 'Token for backend to fetch articles', + type: 'read-only', + permissions: [], + lifespan: null, // Unlimited + }); + + console.log('✅ API Token created successfully!'); + console.log('\nToken details:'); + console.log('Name:', token.name); + console.log('Type:', token.type); + console.log('\nTOKEN (copy this to Coolify as STRAPI_API_TOKEN):'); + console.log(token.accessKey); + console.log('\n⚠️ Save this token - you won\'t see it again!'); + + } catch (error) { + console.error('❌ Error creating API token:', error.message); + } finally { + await strapi.destroy(); + } +} + +createApiToken(); diff --git a/docker-compose.coolify.yml b/docker-compose.coolify.yml index 132787e..71497e3 100644 --- a/docker-compose.coolify.yml +++ b/docker-compose.coolify.yml @@ -79,7 +79,7 @@ services: JWT_EXPIRATION: '86400' FRONTEND_URL: https://placebo.mk PWA_URL: https://app.placebo.mk - STRAPI_URL: https://cms.placebo.mk + STRAPI_URL: http://cms:1337 STRAPI_API_TOKEN: ${STRAPI_API_TOKEN} VAPID_SUBJECT: ${VAPID_SUBJECT:-mailto:contact@placebo.mk} VAPID_PUBLIC_KEY: ${VAPID_PUBLIC_KEY} @@ -87,6 +87,8 @@ services: depends_on: postgres-backend: condition: service_healthy + cms: + condition: service_healthy healthcheck: test: ['CMD', 'node', '-e', "require('http').get('http://127.0.0.1:3000/api/v1/health', (r) => {if(r.statusCode !== 200) process.exit(1)})"] interval: 30s diff --git a/scripts/create-strapi-token.sh b/scripts/create-strapi-token.sh new file mode 100755 index 0000000..f251881 --- /dev/null +++ b/scripts/create-strapi-token.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# Script to create Strapi API token via command line +# Run this on the VPS: ssh root@109.199.109.108 "bash -s" < create-strapi-token.sh + +echo "Creating Strapi API token..." + +# Execute inside the CMS container +docker exec placebo-cms node -e " +const strapi = require('@strapi/strapi'); + +(async () => { + try { + const app = await strapi.createStrapi().load(); + + const tokenService = app.service('admin::api-token'); + + const token = await tokenService.create({ + name: 'Backend Integration', + description: 'Token for backend to fetch articles', + type: 'read-only', + permissions: [], + lifespan: null, + }); + + console.log('\n✅ API Token created successfully!'); + console.log('\nCopy this token to Coolify as STRAPI_API_TOKEN:'); + console.log(token.accessKey); + console.log(''); + + process.exit(0); + } catch (error) { + console.error('❌ Error:', error.message); + process.exit(1); + } +})(); +"