@lovelybunch/api 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server-with-static.js +58 -7
- package/package.json +1 -1
|
@@ -58,6 +58,46 @@ import * as resourcesById from './routes/api/v1/resources/[id]/route.js';
|
|
|
58
58
|
import * as config from './routes/api/v1/config/route.js';
|
|
59
59
|
import agentsApp from './routes/api/v1/agents/route.js';
|
|
60
60
|
import agentsByIdApp from './routes/api/v1/agents/[id]/route.js';
|
|
61
|
+
// Handle trailing slashes by creating explicit redirect routes
|
|
62
|
+
const trailingSlashRoutes = [
|
|
63
|
+
'/api/v1/proposals/',
|
|
64
|
+
'/api/v1/terminal/sessions/',
|
|
65
|
+
'/api/v1/ai/',
|
|
66
|
+
'/api/v1/chats/',
|
|
67
|
+
'/api/v1/resources/',
|
|
68
|
+
'/api/v1/config/'
|
|
69
|
+
];
|
|
70
|
+
// Add explicit handlers for trailing slash routes that redirect to non-slash versions
|
|
71
|
+
trailingSlashRoutes.forEach(route => {
|
|
72
|
+
const methods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
|
|
73
|
+
methods.forEach(method => {
|
|
74
|
+
app.on(method, route, (c) => {
|
|
75
|
+
const newPath = route.slice(0, -1);
|
|
76
|
+
const url = new URL(c.req.url);
|
|
77
|
+
url.pathname = newPath;
|
|
78
|
+
return c.redirect(url.toString(), 308);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
// Handle trailing slashes for parameterized routes
|
|
83
|
+
app.on(['GET', 'PUT', 'PATCH', 'DELETE'], '/api/v1/proposals/:id/', (c) => {
|
|
84
|
+
const id = c.req.param('id');
|
|
85
|
+
const url = new URL(c.req.url);
|
|
86
|
+
url.pathname = `/api/v1/proposals/${id}`;
|
|
87
|
+
return c.redirect(url.toString(), 308);
|
|
88
|
+
});
|
|
89
|
+
app.on(['GET', 'PUT', 'DELETE'], '/api/v1/chats/:id/', (c) => {
|
|
90
|
+
const id = c.req.param('id');
|
|
91
|
+
const url = new URL(c.req.url);
|
|
92
|
+
url.pathname = `/api/v1/chats/${id}`;
|
|
93
|
+
return c.redirect(url.toString(), 308);
|
|
94
|
+
});
|
|
95
|
+
app.on(['GET'], '/api/v1/resources/:id/', (c) => {
|
|
96
|
+
const id = c.req.param('id');
|
|
97
|
+
const url = new URL(c.req.url);
|
|
98
|
+
url.pathname = `/api/v1/resources/${id}`;
|
|
99
|
+
return c.redirect(url.toString(), 308);
|
|
100
|
+
});
|
|
61
101
|
// Register API routes - individual handlers
|
|
62
102
|
app.get('/api/v1/proposals', proposals.GET);
|
|
63
103
|
app.post('/api/v1/proposals', proposals.POST);
|
|
@@ -104,15 +144,26 @@ for (const possiblePath of possibleStaticPaths) {
|
|
|
104
144
|
}
|
|
105
145
|
}
|
|
106
146
|
if (staticPath) {
|
|
107
|
-
// Serve static
|
|
108
|
-
app.use('/*', serveStatic({
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
147
|
+
// Serve static assets
|
|
148
|
+
app.use('/assets/*', serveStatic({ root: staticPath }));
|
|
149
|
+
// Serve specific static files
|
|
150
|
+
app.use('/vite.svg', serveStatic({ root: staticPath }));
|
|
151
|
+
app.use('/favicon.ico', serveStatic({ root: staticPath }));
|
|
152
|
+
// Serve index.html for all non-API, non-WebSocket routes (SPA routing)
|
|
153
|
+
app.get('*', async (c) => {
|
|
154
|
+
const requestPath = c.req.path;
|
|
155
|
+
// Don't serve index.html for API or WebSocket routes
|
|
156
|
+
if (requestPath.startsWith('/api/') || requestPath.startsWith('/ws/')) {
|
|
157
|
+
return c.text('Not Found', 404);
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
112
160
|
const html = fs.readFileSync(path.join(staticPath, 'index.html'), 'utf-8');
|
|
113
|
-
c.html(html);
|
|
161
|
+
return c.html(html);
|
|
114
162
|
}
|
|
115
|
-
|
|
163
|
+
catch (error) {
|
|
164
|
+
return c.text('Not Found', 404);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
116
167
|
}
|
|
117
168
|
// Export function to start the server
|
|
118
169
|
export async function startServer(options = {}) {
|