mirror of
https://github.com/wassname/talk.git
synced 2026-07-27 11:28:12 +08:00
37 lines
809 B
TypeScript
37 lines
809 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.get("/", cacheHeadersMiddleware(cacheDuration), (req, res) =>
|
|
res.render(view, { staticURI })
|
|
);
|
|
|
|
return router;
|
|
}
|