Added static file middleware
This commit is contained in:
parent
1cada0f34d
commit
9cbae3b8a1
1 changed files with 22 additions and 0 deletions
22
src/middleware/static-files.ts
Normal file
22
src/middleware/static-files.ts
Normal file
|
@ -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
|
||||||
|
});
|
||||||
|
}
|
Reference in a new issue