mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 10:24:02 +00:00
fix: return JSON errors for unmatched local API routes
Test development and built-preview route registration, preserve development-only credential editing, and document local preview configuration.
This commit is contained in:
1 parent
a0f07b752f
commit
280fc00a51
8 files changed
+205
-4
No files matched your search
@@ -0,0 +1,17 @@
|
||||
/** Finish unmatched API requests before Vite's HTML fallback. Install last. */
|
||||
export function apiNotFoundPlugin() {
|
||||
const install = (server) => {
|
||||
server.middlewares.use('/api', (_req, res) => {
|
||||
res.writeHead(404, {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-store',
|
||||
});
|
||||
res.end(JSON.stringify({ error: 'Unknown API route' }));
|
||||
});
|
||||
};
|
||||
return {
|
||||
name: 'api-not-found',
|
||||
configureServer: install,
|
||||
configurePreviewServer: install,
|
||||
};
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { fileURLToPath } from 'node:url';
|
||||
import { defineConfig, loadEnv } from 'vite';
|
||||
import { createBrowserViteConfig } from '../../build/vite.js';
|
||||
import { localProviderPlugins } from '../providers/local.js';
|
||||
import { apiNotFoundPlugin } from './api-not-found.js';
|
||||
|
||||
const root = fileURLToPath(new URL('../../', import.meta.url));
|
||||
|
||||
@@ -12,7 +13,7 @@ export default defineConfig(({ mode }) => {
|
||||
if (process.env[key] === undefined) process.env[key] = value;
|
||||
}
|
||||
return createBrowserViteConfig({
|
||||
plugins: localProviderPlugins(),
|
||||
plugins: [...localProviderPlugins(), apiNotFoundPlugin()],
|
||||
googleApiKey: process.env.GOOGLE_MAPS_API_KEY,
|
||||
cesiumToken: process.env.CESIUM_ION_TOKEN,
|
||||
host: process.env.HOST,
|
||||
|
||||
Reference in new issue
Block a user