fix: Catch no path passed to /static/ route

This commit is contained in:
Tom Moor
2022-01-04 20:28:19 -08:00
parent 09df6fa0d1
commit a01dded55a

View File

@@ -8,6 +8,7 @@ import serve from "koa-static";
import isUUID from "validator/lib/isUUID";
import { languages } from "@shared/i18n";
import env from "@server/env";
import { NotFoundError } from "@server/errors";
import Share from "@server/models/Share";
import { opensearchResponse } from "@server/utils/opensearch";
import prefetchTags from "@server/utils/prefetchTags";
@@ -99,7 +100,12 @@ koa.use(
if (process.env.NODE_ENV === "production") {
router.get("/static/*", async (ctx) => {
try {
await send(ctx, ctx.path.substring(8), {
const pathname = ctx.path.substring(8);
if (!pathname) {
throw NotFoundError();
}
await send(ctx, pathname, {
root: path.join(__dirname, "../../app/"),
setHeaders: (res) => {
res.setHeader("Service-Worker-Allowed", "/");