Serve static files extra early to avoid useless middlewares execution

This commit is contained in:
Alice Gaudon 2020-07-28 12:11:10 +02:00
parent 272688da26
commit 31f974c0a6
2 changed files with 10 additions and 5 deletions

View File

@ -12,7 +12,7 @@ export default class ServeStaticDirectoryComponent extends ApplicationComponent<
this.path = routePath;
}
public async handle(router: Router): Promise<void> {
public async init(router: Router): Promise<void> {
if (typeof this.path !== 'undefined') {
router.use(this.path, express.static(this.root, {maxAge: 1000 * 3600 * 72}));
} else {

View File

@ -15,6 +15,7 @@ import AuthGuard from "../src/auth/AuthGuard";
import MagicLink from "../src/auth/models/MagicLink";
import FormHelperComponent from "../src/components/FormHelperComponent";
import RedirectBackComponent from "../src/components/RedirectBackComponent";
import ServeStaticDirectoryComponent from "../src/components/ServeStaticDirectoryComponent";
export default function useApp(appSupplier?: (port: number) => TestApp) {
let app: Application;
@ -53,15 +54,19 @@ export class TestApp extends Application {
}
protected registerComponents() {
const expressAppComponent = new ExpressAppComponent(this.port);
const redisComponent = new RedisComponent();
const mysqlComponent = new MysqlComponent();
const expressAppComponent = new ExpressAppComponent(this.port);
this.use(expressAppComponent);
// Base
this.use(new NunjucksComponent('test/views'));
this.use(expressAppComponent);
this.use(new LogRequestsComponent());
// Static files
this.use(new ServeStaticDirectoryComponent('public'));
// Dynamic views and routes
this.use(new NunjucksComponent('test/views'));
this.use(new RedirectBackComponent());
// Services