fix: use internal Docker network for backend-to-CMS communication
- Changed STRAPI_URL from https://cms.placebo.mk to http://cms:1337 - Added cms dependency to backend service - This fixes Gateway Timeout errors when backend tries to fetch from Strapi - Enables proper container-to-container communication
This commit is contained in:
parent
4f30542014
commit
c1b49a4cb6
1
cms/cms/cmstoken.md
Normal file
1
cms/cms/cmstoken.md
Normal file
@ -0,0 +1 @@
|
||||
ad31a55be0b5efc2d6d7b5490e8d1a31b1a3a2aecbcf99e8f65bcb44bd0189e2918388b942fb3ac7b35fd470d19d475e556489b773c68756977e452aec1ab83f34876ed76ebadafce31636d5621c66820425d1105d753cdc5452d8f3d503ddbaebf45fc6817c235e1f8eae12d118452951ee0a48691446475f7ffc6a72fd6ffb
|
||||
2
cms/cms/envprodstrapi.md
Normal file
2
cms/cms/envprodstrapi.md
Normal file
@ -0,0 +1,2 @@
|
||||
api token=5af45b836a0bcd065b528963e62b6d5d325117dfbf179cd5123087a17906c911fd67bcb57d92f11e869ebda27339b21aa3a7221d3dbbe79de51ef2f9e2af4dae0befe6528872ca2f68f64656ed45c7dfcacea36fdb55d1d9eb2fd9275454ac7ff8ab9acb1535f62449b3f8bd75c24803a2bd0714c637fd1d0bc819798723d999
|
||||
|
||||
38
cms/cms/scripts/create-api-token.js
Normal file
38
cms/cms/scripts/create-api-token.js
Normal file
@ -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();
|
||||
@ -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
|
||||
|
||||
36
scripts/create-strapi-token.sh
Executable file
36
scripts/create-strapi-token.sh
Executable file
@ -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);
|
||||
}
|
||||
})();
|
||||
"
|
||||
Loading…
Reference in New Issue
Block a user