jormungandr-bite/packages/backend/src/server/proxy/index.ts

30 lines
536 B
TypeScript
Raw Normal View History

/**
* Media Proxy
*/
2023-01-12 21:40:33 -07:00
import Koa from "koa";
import cors from "@koa/cors";
import Router from "@koa/router";
import { proxyMedia } from "./proxy-media.js";
// Init app
const app = new Koa();
app.use(cors());
app.use(async (ctx, next) => {
2023-01-12 21:40:33 -07:00
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();
2023-01-12 21:40:33 -07:00
router.get("/:url*", proxyMedia);
// Register router
app.use(router.routes());
export default app;