Add caddy file and update docker compose. Added IMS_TOKEN validation.
This commit is contained in:
28
util/validateToken.ts
Normal file
28
util/validateToken.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import dotenv from "dotenv";
|
||||
import { resolve } from "path";
|
||||
import { logger } from "../server";
|
||||
|
||||
dotenv.config({
|
||||
path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`),
|
||||
});
|
||||
|
||||
export default function ValidateImsToken(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const jobid: string = (req.body.jobid || "").trim();
|
||||
|
||||
const IMS_TOKEN: string = (process.env.IMS_TOKEN || "").trim();
|
||||
|
||||
if (IMS_TOKEN === "") {
|
||||
next();
|
||||
} else {
|
||||
if (req.headers.ims_token !== IMS_TOKEN) {
|
||||
res.sendStatus(401);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user