fake-log/app.js

90 lines
3.7 KiB
JavaScript
Raw Normal View History

2017-12-11 17:21:25 +01:00
const express = require('express');
const path = require('path');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
2019-04-09 19:34:35 +02:00
const cors = require("cors");
const protocol = require("./src/utils/connection");
2017-12-11 17:21:25 +01:00
// const favicon = require('serve-favicon');
2017-09-02 23:45:34 +02:00
2017-12-11 17:21:25 +01:00
const subdomain = require('express-subdomain');
2017-12-11 17:37:46 +01:00
const index = require('./src/routes/index');
2020-02-11 18:09:23 +01:00
const api = require('./src/routes/api');
2017-12-11 17:37:46 +01:00
const cufs = require('./src/routes/cufs');
const uonetplus = require('./src/routes/uonetplus');
const uonetplusOpiekun = require('./src/routes/uonetplus-opiekun');
const uonetplusUczen = require('./src/routes/uonetplus-uczen');
const uonetplusUczenplus = require('./src/routes/uonetplus-uczenplus/index');
2017-12-11 17:37:46 +01:00
const uonetplusUzytkownik = require('./src/routes/uonetplus-uzytkownik');
2022-08-20 16:17:58 +02:00
const uonetplusWiadomosciplus = require('./src/routes/uonetplus-wiadomosciplus');
2017-09-02 23:45:34 +02:00
2017-12-11 16:50:24 +01:00
const app = express();
2017-09-02 23:45:34 +02:00
// view engine setup
2017-12-11 17:37:46 +01:00
app.set('views', path.join(__dirname, 'src/views'));
2017-12-04 18:08:48 +01:00
app.set('view engine', 'pug');
2017-09-02 23:45:34 +02:00
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
2017-12-11 16:50:24 +01:00
app.use((req, res, next) => {
2018-12-11 20:00:14 +01:00
res.locals.userInfo = require('./data/api/ListaUczniow')[1];
res.locals.uonetplusUrl = protocol(req) + "://" + req.get('host').replace("uonetplus-opiekun", "uonetplus");
res.locals.currentHost = protocol(req) + "://" + req.get('host');
2019-05-17 20:10:06 +02:00
res.locals.proto = protocol(req);
res.locals.host = req.get('host').replace(/(api|cufs|uonetplus|uonetplus-opiekun|uonetplus-uzytkownik)\./, "");
2019-10-31 16:01:42 +01:00
res.cookie("UonetPlus_ASP.NET_SessionId", "", { httpOnly: true, domain: req.get("host") });
res.cookie("ARR_DS_ARR301302", "", { httpOnly: true, domain: req.get("host") });
res.cookie("ARR_" + req.get('host'), "1234567891012131314151617181920212223242526272829303132333435363", { httpOnly: true, domain: req.get("host") });
2017-12-04 20:58:22 +01:00
next();
});
2019-04-09 19:34:35 +02:00
const corsOpt = {
origin: process.env.CORS_ALLOW_ORIGIN || '*'
};
app.use(cors(corsOpt));
app.options('*', cors(corsOpt));
2020-05-12 13:55:23 +02:00
app.set('subdomain offset', +process.env.SUBDOMAIN_OFFSET || 2);
2018-07-12 15:14:45 +02:00
app.use(subdomain('api', api));
2017-11-28 16:45:37 +01:00
app.use(subdomain('cufs', cufs));
app.use(subdomain('uonetplus', uonetplus));
app.use(subdomain('uonetplus-opiekun', uonetplusOpiekun.use('/powiatwulkanowy/123456', uonetplusOpiekun)));
app.use(subdomain('uonetplus-opiekun', uonetplusOpiekun.use('/powiatwulkanowy/123457', uonetplusOpiekun)));
app.use(subdomain('uonetplus-opiekun', uonetplusOpiekun.use('/powiatwulkanowy/123458', uonetplusOpiekun)));
app.use(subdomain('uonetplus-uczen', uonetplusUczen.use('/powiatwulkanowy/:customerSymbol', uonetplusUczen)));
app.use(subdomain("uonetplus-uczenplus", uonetplusUczenplus.use("/powiatwulkanowy/:customerSymbol", uonetplusUczenplus)));
app.use(subdomain('uonetplus-uzytkownik', uonetplusUzytkownik.use('/powiatwulkanowy', uonetplusUzytkownik)));
2022-08-20 16:17:58 +02:00
app.use(subdomain('uonetplus-wiadomosciplus', uonetplusWiadomosciplus.use('/powiatwulkanowy', uonetplusWiadomosciplus)));
2017-09-02 23:45:34 +02:00
app.use('/', index);
// catch 404 and forward to error handler
2017-12-11 16:50:24 +01:00
app.use((req, res, next) => {
const err = new Error('Not Found');
2017-09-02 23:45:34 +02:00
err.status = 404;
next(err);
});
// error handler
2017-12-11 16:50:24 +01:00
app.use((err, req, res, next) => {
2017-09-02 23:45:34 +02:00
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
2017-12-06 21:08:28 +01:00
if (typeof(PhusionPassenger) !== 'undefined') {
app.listen('passenger');
}
2017-09-02 23:45:34 +02:00
module.exports = app;