Skip to content

Commit c8faecf

Browse files
Merge pull request #7 from codebuilderinc/refactor/remove-graphql-rest-consolidation
Removed /api/ path prefix.
2 parents 0893551 + d907831 commit c8faecf

File tree

2 files changed

+3
-30
lines changed

2 files changed

+3
-30
lines changed

src/common/configs/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const config: Config = {
1212
title: 'CodeBuilder API',
1313
description: 'CodeBuilder Website & Mobile App API.',
1414
version: '1.5',
15-
path: 'api',
15+
path: 'docs',
1616
},
1717
security: {
1818
expiresIn: '2m',

src/main.ts

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -80,33 +80,6 @@ async function bootstrap(): Promise<void> {
8080
credentials: true,
8181
});
8282

83-
// Support requests without the `/api` prefix by adding it automatically.
84-
// Routes are registered under /api/* via RouterModule, so this lets both
85-
// `/jobs` and `/api/jobs` work without changing controllers.
86-
// NOTE: We exclude Swagger paths from rewriting.
87-
const swaggerPath = swaggerConfig.path || 'api';
88-
app.use((req: any, _res, next) => {
89-
if (typeof req.url === 'string') {
90-
const urlPath = req.url.split('?')[0];
91-
92-
// Skip if already has /api prefix
93-
if (req.url.startsWith('/api')) {
94-
return next();
95-
}
96-
97-
// Skip root path, health checks, and other special paths
98-
if (urlPath === '/' || urlPath === '/health') {
99-
return next();
100-
}
101-
102-
// Add /api prefix to the request
103-
const newUrl = `/api${req.url}`;
104-
req.url = newUrl;
105-
req.originalUrl = newUrl;
106-
}
107-
next();
108-
});
109-
11083
// ===================================
11184
// Global Setup
11285
// ===================================
@@ -158,7 +131,7 @@ async function bootstrap(): Promise<void> {
158131
.addBearerAuth() // If you use Bearer token authentication
159132
.build();
160133
const document = SwaggerModule.createDocument(app, options);
161-
SwaggerModule.setup(swaggerConfig.path || 'api/docs', app, document);
134+
SwaggerModule.setup(swaggerConfig.path || 'docs', app, document);
162135
}
163136

164137
// ===================================
@@ -175,7 +148,7 @@ async function bootstrap(): Promise<void> {
175148
await app.listen(port, '0.0.0.0');
176149
console.log(`🚀 CodeBuilder API is listening on http://localhost:${port}`);
177150
if (swaggerConfig.enabled) {
178-
console.log(`📚 Swagger Docs available at http://localhost:${port}/${swaggerConfig.path || 'api/docs'}`);
151+
console.log(`📚 Swagger Docs available at http://localhost:${port}/${swaggerConfig.path || 'docs'}`);
179152
}
180153
}
181154

0 commit comments

Comments
 (0)