fake-log/app.js

103 lines
3.7 KiB
JavaScript
Raw Normal View History

2024-03-28 10:47:46 +01:00
const express = require('express');
const path = require('path');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
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
2024-03-28 10:47:46 +01:00
const subdomain = require('express-subdomain');
const index = require('./src/routes/index');
const api = require('./src/routes/api');
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');
const uonetplusUzytkownik = require('./src/routes/uonetplus-uzytkownik');
const uonetplusWiadomosciplus = require('./src/routes/uonetplus-wiadomosciplus');
2017-09-02 23:45:34 +02:00
2024-03-28 10:47:46 +01:00
const app = express();
2017-09-02 23:45:34 +02:00
// view engine setup
2024-03-28 10:47:46 +01:00
app.set('views', path.join(__dirname, 'src/views'));
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')));
2024-03-28 10:47:46 +01:00
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-09-02 23:45:34 +02:00
2017-12-11 16:50:24 +01:00
app.use((req, res, next) => {
2024-03-28 10:47:46 +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');
res.locals.proto = protocol(req);
res.locals.host = req.get('host').replace(/(api|cufs|uonetplus|uonetplus-opiekun|uonetplus-uzytkownik)\./, '');
2024-03-27 22:31:41 +01:00
res.cookie('UonetPlus_ASP.NET_SessionId', '', {
httpOnly: true,
domain: req.get('host'),
2024-03-28 10:47:46 +01:00
});
2024-03-27 22:31:41 +01:00
res.cookie('ARR_DS_ARR301302', '', {
httpOnly: true,
domain: req.get('host'),
2024-03-28 10:47:46 +01:00
});
2024-03-27 22:31:41 +01:00
res.cookie('ARR_' + req.get('host'), '1234567891012131314151617181920212223242526272829303132333435363', {
httpOnly: true,
domain: req.get('host'),
2024-03-28 10:47:46 +01:00
});
next();
});
2017-12-04 20:58:22 +01:00
2019-04-09 19:34:35 +02:00
const corsOpt = {
2024-03-27 22:31:41 +01:00
origin: process.env.CORS_ALLOW_ORIGIN || '*',
2024-03-28 10:47:46 +01:00
};
app.use(cors(corsOpt));
app.options('*', cors(corsOpt));
2019-04-09 19:34:35 +02:00
2024-03-28 10:47:46 +01:00
app.set('subdomain offset', +process.env.SUBDOMAIN_OFFSET || 2);
app.use(subdomain('api', api));
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)));
app.use(
subdomain('uonetplus-wiadomosciplus', uonetplusWiadomosciplus.use('/powiatwulkanowy', uonetplusWiadomosciplus))
);
app.use('/', index);
2017-09-02 23:45:34 +02:00
// catch 404 and forward to error handler
2017-12-11 16:50:24 +01:00
app.use((req, res, next) => {
2024-03-28 10:47:46 +01:00
const err = new Error('Not Found');
err.status = 404;
next(err);
});
2017-09-02 23:45:34 +02:00
// 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
2024-03-28 10:47:46 +01:00
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
2017-09-02 23:45:34 +02:00
// render the error page
2024-03-28 10:47:46 +01:00
res.status(err.status || 500);
res.render('error');
});
2017-09-02 23:45:34 +02:00
2024-03-27 22:31:41 +01:00
if (typeof PhusionPassenger !== 'undefined') {
2024-03-28 10:47:46 +01:00
app.listen('passenger');
2017-12-06 21:08:28 +01:00
}
2024-03-28 10:47:46 +01:00
module.exports = app;