@lovelybunch/api 1.0.8 → 1.0.9
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 +18 -7
- package/package.json +1 -1
|
@@ -104,15 +104,26 @@ for (const possiblePath of possibleStaticPaths) {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
if (staticPath) {
|
|
107
|
-
// Serve static
|
|
108
|
-
app.use('/*', serveStatic({
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
// Serve static assets
|
|
108
|
+
app.use('/assets/*', serveStatic({ root: staticPath }));
|
|
109
|
+
// Serve specific static files
|
|
110
|
+
app.use('/vite.svg', serveStatic({ root: staticPath }));
|
|
111
|
+
app.use('/favicon.ico', serveStatic({ root: staticPath }));
|
|
112
|
+
// Serve index.html for all non-API, non-WebSocket routes (SPA routing)
|
|
113
|
+
app.get('*', async (c) => {
|
|
114
|
+
const requestPath = c.req.path;
|
|
115
|
+
// Don't serve index.html for API or WebSocket routes
|
|
116
|
+
if (requestPath.startsWith('/api/') || requestPath.startsWith('/ws/')) {
|
|
117
|
+
return c.text('Not Found', 404);
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
112
120
|
const html = fs.readFileSync(path.join(staticPath, 'index.html'), 'utf-8');
|
|
113
|
-
c.html(html);
|
|
121
|
+
return c.html(html);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
return c.text('Not Found', 404);
|
|
114
125
|
}
|
|
115
|
-
})
|
|
126
|
+
});
|
|
116
127
|
}
|
|
117
128
|
// Export function to start the server
|
|
118
129
|
export async function startServer(options = {}) {
|