fix: resolve API URL duplication, CORS issues, and image localhost URLs
- Fix duplicate /api/v1 in analytics.ts API calls - Add STRAPI_PUBLIC_URL env var for public CMS access - Update strapi.service to use public URL for images instead of localhost - Images now use https://cms.placebo.mk instead of http://localhost:1337
This commit is contained in:
1 parent
ebd1fc28d5
commit
a66db56156
3 files changed
+15
-14
No files matched your search
@@ -87,6 +87,7 @@ interface StrapiResponse<T> {
|
||||
export class StrapiService {
|
||||
private readonly logger = new Logger(StrapiService.name);
|
||||
private readonly strapiUrl: string;
|
||||
private readonly strapiPublicUrl: string;
|
||||
private readonly strapiApiToken: string;
|
||||
|
||||
constructor(
|
||||
@@ -101,6 +102,9 @@ export class StrapiService {
|
||||
) {
|
||||
this.strapiUrl =
|
||||
this.configService.get<string>('STRAPI_URL') || 'http://localhost:1337';
|
||||
this.strapiPublicUrl =
|
||||
this.configService.get<string>('STRAPI_PUBLIC_URL') ||
|
||||
this.strapiUrl.replace('cms:', 'localhost:');
|
||||
this.strapiApiToken =
|
||||
this.configService.get<string>('STRAPI_API_TOKEN') || '';
|
||||
}
|
||||
@@ -182,10 +186,8 @@ export class StrapiService {
|
||||
|
||||
// If URL is relative, prepend Strapi base URL
|
||||
if (imageUrl.startsWith('/')) {
|
||||
// Convert Docker service URL to localhost for frontend access
|
||||
// Backend uses http://cms:1337 internally, but frontend needs http://localhost:1337
|
||||
const frontendStrapiUrl = this.strapiUrl.replace('cms:', 'localhost:');
|
||||
return `${frontendStrapiUrl}${imageUrl}`;
|
||||
// Use public URL for frontend access
|
||||
return `${this.strapiPublicUrl}${imageUrl}`;
|
||||
}
|
||||
|
||||
return imageUrl;
|
||||
@@ -210,10 +212,8 @@ export class StrapiService {
|
||||
|
||||
// If URL is relative, prepend Strapi base URL
|
||||
if (imageUrl.startsWith('/')) {
|
||||
// Convert Docker service URL to localhost for frontend access
|
||||
// Backend uses http://cms:1337 internally, but frontend needs http://localhost:1337
|
||||
const frontendStrapiUrl = this.strapiUrl.replace('cms:', 'localhost:');
|
||||
return `${frontendStrapiUrl}${imageUrl}`;
|
||||
// Use public URL for frontend access
|
||||
return `${this.strapiPublicUrl}${imageUrl}`;
|
||||
}
|
||||
|
||||
return imageUrl;
|
||||
|
||||
Reference in new issue
Block a user