Fix some shenanigans with routes

This commit is contained in:
Jesse Wierzbinski 2024-03-10 20:22:48 -10:00
parent 04dcaa94aa
commit 4755451404
No known key found for this signature in database
4 changed files with 16 additions and 15 deletions

BIN
bun.lockb

Binary file not shown.

View file

@ -68,11 +68,11 @@
"eslint-formatter-summary": "^1.1.0",
"eslint-plugin-prettier": "^5.0.1",
"prettier": "^3.1.0",
"typescript": "^5.3.2",
"typescript": "latest",
"unocss": "latest",
"@vitejs/plugin-vue": "latest",
"@vueuse/head": "^2.0.0",
"vite": "^5.0.4",
"vite": "latest",
"vite-ssr": "^0.17.1",
"vue": "^3.3.9",
"vue-router": "^4.2.5",

View file

@ -1,3 +1,4 @@
import type { RouteRecordRaw } from "vue-router";
import indexVue from "./pages/index.vue";
import authorizeVue from "./pages/oauth/authorize.vue";
import registerIndexVue from "./pages/register/index.vue";
@ -8,4 +9,4 @@ export default [
{ path: "/oauth/authorize", component: authorizeVue },
{ path: "/register", component: registerIndexVue },
{ path: "/register/success", component: successVue },
];
] as RouteRecordRaw[];

View file

@ -137,7 +137,11 @@ export const createServer = (
configManager,
parsedRequest,
});
} else if (matchedRoute?.name === "/[...404]") {
} else if (matchedRoute?.name === "/[...404]" || !matchedRoute) {
if (new URL(req.url).pathname.startsWith("/api")) {
return errorResponse("Route not found", 404);
}
// Proxy response from Vite at localhost:5173 if in development mode
if (isProd) {
if (new URL(req.url).pathname.startsWith("/assets")) {
@ -164,21 +168,17 @@ export const createServer = (
config.http.base_url,
"http://localhost:5173"
)
).catch(async e => {
await logger.logError(
LogLevel.ERROR,
"Server.Proxy",
e as Error
);
return errorResponse("Route not found", 404);
});
if (proxy.status !== 404) {
if (
proxy.status !== 404 &&
!(await proxy.clone().text()).includes("404 Not Found")
) {
return proxy;
}
}
return errorResponse("Route not found", 404);
}
} else {
return errorResponse("Route not found", 404);
}