|
| 1 | +/* |
| 2 | + * Copyright (c) 2020 The Web eID Project |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | + * of this software and associated documentation files (the "Software"), to deal |
| 6 | + * in the Software without restriction, including without limitation the rights |
| 7 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | + * copies of the Software, and to permit persons to whom the Software is |
| 9 | + * furnished to do so, subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in all |
| 12 | + * copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | + * SOFTWARE. |
| 21 | + */ |
| 22 | + |
| 23 | +const path = require("path"); |
| 24 | +const express = require("express"); |
| 25 | +const cookieParser = require("cookie-parser"); |
| 26 | +const logger = require("morgan"); |
| 27 | +const helmet = require("helmet"); |
| 28 | + |
| 29 | +const IndexController = require("./controllers/RootController"); |
| 30 | +const AuthController = require("./controllers/AuthController"); |
| 31 | +const SignController = require("./controllers/SignController"); |
| 32 | + |
| 33 | +const controllers = [ |
| 34 | + new IndexController(), |
| 35 | + new AuthController(), |
| 36 | + new SignController(), |
| 37 | +]; |
| 38 | + |
| 39 | +const app = express(); |
| 40 | + |
| 41 | +// view engine setup |
| 42 | +app.set("views", path.join(__dirname, "views")); |
| 43 | +app.set("view engine", "hbs"); |
| 44 | + |
| 45 | +if (!process.argv.slice(2).includes("--no-csp")) { |
| 46 | + app.use(helmet.contentSecurityPolicy()); |
| 47 | +} |
| 48 | + |
| 49 | +app.use(helmet.dnsPrefetchControl()); |
| 50 | +app.use(helmet.expectCt()); |
| 51 | +app.use(helmet.frameguard()); |
| 52 | +app.use(helmet.hidePoweredBy()); |
| 53 | +app.use(helmet.hsts()); |
| 54 | +app.use(helmet.ieNoOpen()); |
| 55 | +app.use(helmet.noSniff()); |
| 56 | +app.use(helmet.permittedCrossDomainPolicies()); |
| 57 | +app.use(helmet.referrerPolicy()); |
| 58 | +app.use(helmet.xssFilter()); |
| 59 | + |
| 60 | +app.use(logger("dev")); |
| 61 | +app.use(express.json()); |
| 62 | +app.use(express.urlencoded({ extended: false })); |
| 63 | +app.use(cookieParser()); |
| 64 | +app.use(express.static(path.join(__dirname, "public"))); |
| 65 | +app.use("/lib", express.static(path.join(__dirname, "../node_modules/@web-eid/web-eid-library/dist/"))); |
| 66 | + |
| 67 | +app.get("/", (req, res) => res.render("index", { |
| 68 | + tokenSigning: req.query.tokenSigning == "true", |
| 69 | +})); |
| 70 | + |
| 71 | +app.get("/webeid", (req, res) => res.render("webeid", { |
| 72 | + tokenSigning: req.query.tokenSigning == "true", |
| 73 | +})); |
| 74 | + |
| 75 | +app.get("/hwcrypto", (req, res) => res.render("hwcrypto", { |
| 76 | + tokenSigning: req.query.tokenSigning == "true", |
| 77 | +})); |
| 78 | + |
| 79 | +controllers.forEach((controller) => app.use("/", controller.router)); |
| 80 | + |
| 81 | +module.exports = app; |
0 commit comments