From 5717af872df070a50b9c27ccb21e2753339ae8fe Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Fri, 1 Apr 2022 17:50:13 +0200 Subject: Attempt to add basic SAML Signed-off-by: Matt Strapp --- src/index.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/index.ts') diff --git a/src/index.ts b/src/index.ts index 117f0f1..c4b346a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,12 @@ import rateLimit from 'express-rate-limit'; import helmet from 'helmet'; import path from 'path'; import { env } from 'process'; -import api from './routes/pendulum'; +import api from './routes/api.js'; +import saml from './routes/middleware/saml.js'; +import { dirname } from 'path'; +import { fileURLToPath } from 'url'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); const app = express(); @@ -21,7 +26,7 @@ const csrf = csurf({ cookie: true }); // Rate limiting const rateLimiter = rateLimit({ windowMs: 1 * 60 * 1000, // 1 minute - max: 40, // Limit each IP to 40 requests per `window` (here, per 1 minutes) + max: 40, // Limit each IP to 40 requests per `window` (here, per 1 minute) standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers legacyHeaders: false, // Disable the `X-RateLimit-*` headers }); @@ -33,7 +38,7 @@ app.use('/api/v1/', api); /* RENDERING */ app.set('view engine', 'ejs'); // Add ejs as view engine -app.set('views', path.join(__dirname, 'views/pages')); // Set views directory (where the ejs lies) +app.set('views', path.join(__dirname, 'views/pages')); // Set views directory (where the ejs is) app.use('/public', express.static(path.join(__dirname, 'public'))); // Set static directory (where the static CSS/JS/images lie) /* ROUTING */ @@ -41,9 +46,12 @@ app.use('/public', express.static(path.join(__dirname, 'public'))); // Set stati app.get('/', csrf, (req: Request, res: Response) => { res.render('index', { csrfToken: req.csrfToken() }); }); -app.get('/about', csrf, (req: Request, res: Response) => { +app.get('/about', csrf, saml, (req: Request, res: Response) => { res.render('about'); }); +app.all('/login', csrf, (req: Request, res: Response) => { + res.redirect('/api/v1/login'); +}); // Start the server const port = env.PORT || 2000; -- cgit v1.2.3