Express static does not set correct header so setting manual
This commit is contained in:
parent
f9083a1d27
commit
be8a2f7b2c
@ -1,4 +1,10 @@
|
||||
import { IRouter, Request, Router, static as ServeStatic } from "express";
|
||||
import {
|
||||
IRouter,
|
||||
Request,
|
||||
Router,
|
||||
static as ServeStatic,
|
||||
RequestHandler,
|
||||
} from "express";
|
||||
import * as Handlebars from "handlebars";
|
||||
import * as moment from "moment";
|
||||
import { GetUserMiddleware, UserMiddleware } from "../api/middlewares/user";
|
||||
@ -12,9 +18,14 @@ import GetRegistrationPage from "./register";
|
||||
Handlebars.registerHelper("appname", () => config.core.name);
|
||||
|
||||
const cacheTime = config.core.dev
|
||||
? moment.duration(1, "month").asMilliseconds()
|
||||
? moment.duration(1, "month").asSeconds()
|
||||
: 1000;
|
||||
|
||||
const addCache: RequestHandler = (req, res, next) => {
|
||||
res.setHeader("cache-control", "public, max-age=" + cacheTime);
|
||||
next();
|
||||
};
|
||||
|
||||
const ViewRouter: IRouter = Router();
|
||||
ViewRouter.get("/", UserMiddleware, (req, res) => {
|
||||
res.send("This is the main page");
|
||||
@ -27,12 +38,14 @@ ViewRouter.get("/register", (req, res) => {
|
||||
|
||||
ViewRouter.use(
|
||||
"/login",
|
||||
ServeStatic("./views_repo/build/login", { maxAge: cacheTime })
|
||||
addCache,
|
||||
ServeStatic("./views_repo/build/login", { cacheControl: false })
|
||||
);
|
||||
|
||||
ViewRouter.use(
|
||||
"/user",
|
||||
ServeStatic("./views_repo/build/user", { maxAge: cacheTime })
|
||||
addCache,
|
||||
ServeStatic("./views_repo/build/user", { cacheControl: false })
|
||||
);
|
||||
|
||||
ViewRouter.get("/code", (req, res) => {
|
||||
|
Loading…
Reference in New Issue
Block a user