mirror of
https://github.com/wassname/talk.git
synced 2026-07-28 11:27:05 +08:00
* feat: initial csp support * fix: strip non-frame directives * review: added tests, fixed some edge cases
37 lines
817 B
TypeScript
37 lines
817 B
TypeScript
import express from "express";
|
|
|
|
import { cacheHeadersMiddleware } from "talk-server/app/middleware/cacheHeaders";
|
|
|
|
export interface ClientTargetHandlerOptions {
|
|
/**
|
|
* view is the name of the template to render.
|
|
*/
|
|
view: string;
|
|
|
|
/**
|
|
* cacheDuration is the cache duration that a given request should be cached for.
|
|
*/
|
|
cacheDuration?: string | false;
|
|
|
|
/**
|
|
* staticURI is prepended to the static url's that are included on the static
|
|
* pages.
|
|
*/
|
|
staticURI: string;
|
|
}
|
|
|
|
export function createClientTargetRouter({
|
|
staticURI,
|
|
view,
|
|
cacheDuration = "1h",
|
|
}: ClientTargetHandlerOptions) {
|
|
// Create a router.
|
|
const router = express.Router();
|
|
|
|
router.use(cacheHeadersMiddleware(cacheDuration));
|
|
|
|
router.get("/", (req, res) => res.render(view, { staticURI }));
|
|
|
|
return router;
|
|
}
|