diff --git a/src/middleware/static-files.ts b/src/middleware/static-files.ts new file mode 100644 index 0000000..4642a47 --- /dev/null +++ b/src/middleware/static-files.ts @@ -0,0 +1,22 @@ +import express, { Request, Response } from 'express'; +import path from 'path'; + +function isDirectory(url : string) : boolean { + return /\/$/.test(url); +} + +export function indexHandle(request : Request, response : Response, next : Function) { + if (isDirectory(request.url)) { + request.url = path.join(request.url, 'index.html'); + } + return next(); +} + + +export function staticFileHandle(serveDir : string) { + return express.static(serveDir, { + dotfiles: 'ignore', + index: false, + redirect: true + }); +}