rudeshark.net/packages/backend/src/server/proxy/index.ts
shibao 380d14f406
Add img-src and media-src to Content-Security-Policy header for files and media proxy (#8188)
* add img-src and media-src to csp in file and media proxy

* add csp changes to changelog

* sort and remove trailing semicolon
2022-01-29 02:23:18 +09:00

27 lines
542 B
TypeScript

/**
* Media Proxy
*/
import * as Koa from 'koa';
import * as cors from '@koa/cors';
import * as Router from '@koa/router';
import { proxyMedia } from './proxy-media';
// Init app
const app = new Koa();
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('/:url*', proxyMedia);
// Register router
app.use(router.routes());
module.exports = app;