Fixed 267U.pre2
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* File Server
|
||||
*/ import * as fs from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { dirname } from "node:path";
|
||||
import Koa from "koa";
|
||||
import cors from "@koa/cors";
|
||||
import Router from "@koa/router";
|
||||
import sendDriveFile from "./send-drive-file.js";
|
||||
import { serverLogger } from "../index.js";
|
||||
import { isIgnorableConnectionError } from "../is-ignorable-connection-error.js";
|
||||
const _filename = fileURLToPath(import.meta.url);
|
||||
const _dirname = dirname(_filename);
|
||||
// Init app
|
||||
const app = new Koa();
|
||||
app.on("error", (err)=>{
|
||||
if (isIgnorableConnectionError(err)) return;
|
||||
serverLogger.error(err);
|
||||
});
|
||||
app.use(cors());
|
||||
app.use(async (ctx, next)=>{
|
||||
ctx.set("Content-Security-Policy", `default-src 'none'; img-src 'self'; media-src 'self'; style-src 'unsafe-inline'`);
|
||||
await next();
|
||||
});
|
||||
// Init router
|
||||
const router = new Router();
|
||||
router.get("/app-default.jpg", (ctx)=>{
|
||||
const file = fs.createReadStream(`${_dirname}/assets/dummy.png`);
|
||||
ctx.body = file;
|
||||
ctx.set("Content-Type", "image/jpeg");
|
||||
ctx.set("Cache-Control", "max-age=31536000, immutable");
|
||||
});
|
||||
router.get("/:key", sendDriveFile);
|
||||
router.get("/:key/{*splat}", sendDriveFile);
|
||||
// Register router
|
||||
app.use(router.routes());
|
||||
export default app;
|
||||
Reference in New Issue
Block a user