From 965a9852acf939b4da3c418b31fdc4c117efb004 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Mon, 1 Mar 2021 15:10:51 -0600 Subject: send 401 status code when unauthorized --- src/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/index.ts b/src/index.ts index fa3b75f..edef374 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,11 +7,10 @@ const app = express() export const debug = false -app.use((req, res, next) => { +app.use((req: express.Request, res, next) => { if (process.env.key && req.headers.key !== process.env.key) // if a key is set in process.env and the header doesn't match return an error - // TODO: make this have a status code - return res.json({ error: 'Key in header must match key in env' }) + return res.status(401).json({ error: 'Key in header must match key in env' }) next() }) -- cgit