diff --git a/src/middleware/404.ts b/src/middleware/404.ts new file mode 100644 index 0000000..3bb2a29 --- /dev/null +++ b/src/middleware/404.ts @@ -0,0 +1,11 @@ +import { Request, Response } from 'express'; +import staticFile from 'connect-static-file' +import path from 'path'; + +export default function handle404(serveDir : string) { + const handle404Middleware = staticFile(path.join(serveDir, '.404.html')); + return function (request : Request, response : Response, next : Function) { + response.statusCode = 404; + return handle404Middleware(request, response, next); + } +} diff --git a/src/types/fakes.d.ts b/src/types/fakes.d.ts index 45d03bd..b5ddadc 100644 --- a/src/types/fakes.d.ts +++ b/src/types/fakes.d.ts @@ -1,3 +1,4 @@ /* Mock types that dont exist */ declare module 'express-ip-access-control'; +declare module 'connect-static-file';