2020-04-22 15:52:17 +02:00
|
|
|
import ApplicationComponent from "../ApplicationComponent";
|
2020-07-11 11:46:16 +02:00
|
|
|
import express, {Router} from "express";
|
2020-04-22 15:52:17 +02:00
|
|
|
import {PathParams} from "express-serve-static-core";
|
|
|
|
|
|
|
|
export default class ServeStaticDirectoryComponent extends ApplicationComponent<void> {
|
|
|
|
private readonly root: string;
|
|
|
|
private readonly path?: PathParams;
|
|
|
|
|
|
|
|
constructor(root: string, routePath?: PathParams) {
|
|
|
|
super();
|
|
|
|
this.root = root;
|
|
|
|
this.path = routePath;
|
|
|
|
}
|
|
|
|
|
2020-07-11 11:46:16 +02:00
|
|
|
public async handle(router: Router): Promise<void> {
|
2020-04-22 15:52:17 +02:00
|
|
|
if (typeof this.path !== 'undefined') {
|
|
|
|
router.use(this.path, express.static(this.root, {maxAge: 1000 * 3600 * 72}));
|
|
|
|
} else {
|
|
|
|
router.use(express.static(this.root, {maxAge: 1000 * 3600 * 72}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public async stop(): Promise<void> {
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|