From 11cacc5e35710ee9777e516cf5b67da2682fa78f Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 15 Feb 2017 07:32:19 +0000 Subject: [PATCH] Add 404 middleware --- src/middleware/404.ts | 11 +++++++++++ src/types/fakes.d.ts | 1 + 2 files changed, 12 insertions(+) create mode 100644 src/middleware/404.ts 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';