diff --git a/app.js b/app.js index 11b50d2..651cff6 100644 --- a/app.js +++ b/app.js @@ -1,19 +1,19 @@ -var express = require('express'); -var path = require('path'); -var favicon = require('serve-favicon'); -var logger = require('morgan'); -var cookieParser = require('cookie-parser'); -var bodyParser = require('body-parser'); -var sassMiddleware = require('node-sass-middleware'); -var subdomain = require('express-subdomain'); +import express from 'express'; +import path from 'path' +import logger from "morgan"; +// import favicon from "serve-favicon"; +import cookieParser from "cookie-parser"; +import bodyParser from "body-parser"; +import sassMiddleware from "node-sass-middleware"; -var index = require('./routes/index'); -var cufs = require('./routes/cufs'); -var uonetplus = require('./routes/uonetplus'); -var uonetplusOpiekun = require('./routes/uonetplus-opiekun'); -var uonetplusUzytkownik = require('./routes/uonetplus-uzytkownik'); +import subdomain from "express-subdomain"; +import index from "./routes/index"; +import cufs from "./routes/cufs"; +import uonetplus from "./routes/uonetplus"; +import uonetplusOpiekun from "./routes/uonetplus-opiekun"; +import uonetplusUzytkownik from "./routes/uonetplus-uzytkownik"; -var app = express(); +const app = express(); // view engine setup app.set('views', path.join(__dirname, 'views')); @@ -33,7 +33,7 @@ app.use(sassMiddleware({ })); app.use(express.static(path.join(__dirname, 'public'))); -app.use(function (req, res, next) { +app.use((req, res, next) => { res.locals.uonetplusUrl = "http://" + req.get('host').replace("uonetplus-opiekun", "uonetplus"); res.locals.mainHost = "http://" + req.get('host') .replace(/(cufs|uonetplus|uonetplus-opiekun|uonetplus-uzytkownik)\./, ""); @@ -47,14 +47,14 @@ app.use(subdomain('uonetplus-uzytkownik', uonetplusUzytkownik)); app.use('/', index); // catch 404 and forward to error handler -app.use(function(req, res, next) { - var err = new Error('Not Found'); +app.use((req, res, next) => { + const err = new Error('Not Found'); err.status = 404; next(err); }); // error handler -app.use(function(err, req, res, next) { +app.use((err, req, res, next) => { // set locals, only providing error in development res.locals.message = err.message; res.locals.error = req.app.get('env') === 'development' ? err : {}; diff --git a/routes/cufs.js b/routes/cufs.js index c2e94e9..b7e04df 100644 --- a/routes/cufs.js +++ b/routes/cufs.js @@ -1,19 +1,19 @@ -var express = require('express'); -var fs = require('fs'); -var router = express.Router(); -var protocol = require('../utils/connection'); +const express = require('express'); +const fs = require('fs'); +const router = express.Router(); +const protocol = require('../utils/connection'); -router.get("/", function(req, res) { +router.get("/", (req, res) => { res.redirect("/Default/Account/LogOn"); }); // GET login page -router.get("/Default/Account/LogOn", function(req, res) { +router.get("/Default/Account/LogOn", (req, res) => { res.render("login-form", { title: "Logowanie (Default)" }); }); // POST login -router.post("/Default/Account/LogOn", function(req, res) { +router.post("/Default/Account/LogOn", (req, res) => { if ('admin' === req.body.LoginName && 'admin' === req.body.Password) { return res.redirect("/Default/FS/LS?" + "wa=wsignin1.0&" + @@ -24,7 +24,7 @@ router.post("/Default/Account/LogOn", function(req, res) { res.render("login-form", { title: "Logowanie (Default)", message: "Zła nazwa użytkownika lub hasło" }); }); -router.get("/Default/FS/LS", function (req, res) { +router.get("/Default/FS/LS", (req, res) => { res.render("login-cert", { cert: fs.readFileSync("public/cert.xml", "utf8"), uonetplusOpiekun: protocol(req) + "://" + req.get('host').replace("cufs.", "uonetplus.") diff --git a/utils/connection.js b/utils/connection.js index c701303..d773264 100644 --- a/utils/connection.js +++ b/utils/connection.js @@ -1,6 +1,6 @@ function getProtocol(req) { - var proto = req.connection.encrypted ? 'https' : 'http'; + let proto = req.connection.encrypted ? 'https' : 'http'; // only do this if you trust the proxy proto = req.headers['x-forwarded-proto'] || proto; return proto.split(/\s*,\s*/)[0];