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');
|
|
|
|
const sassMiddleware = require('node-sass-middleware');
|
2019-01-11 01:23:29 +01:00
|
|
|
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');
|
2018-07-12 15:14:45 +02:00
|
|
|
const api = require('./src/routes/api/index');
|
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');
|
2018-12-05 01:07:20 +01:00
|
|
|
const uonetplusUczen = require('./src/routes/uonetplus-uczen');
|
2017-12-11 17:37:46 +01:00
|
|
|
const uonetplusUzytkownik = require('./src/routes/uonetplus-uzytkownik');
|
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(sassMiddleware({
|
|
|
|
src: path.join(__dirname, 'public'),
|
|
|
|
dest: path.join(__dirname, 'public'),
|
2017-11-28 14:53:12 +01:00
|
|
|
indentedSyntax: false, // true = .sass and false = .scss
|
2017-09-02 23:45:34 +02:00
|
|
|
sourceMap: true
|
|
|
|
}));
|
|
|
|
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];
|
2019-01-11 01:23:29 +01:00
|
|
|
res.locals.uonetplusUrl = protocol(req) + "://" + req.get('host').replace("uonetplus-opiekun", "uonetplus");
|
|
|
|
res.locals.currentHost = protocol(req) + "://" + req.get('host');
|
|
|
|
res.locals.mainHost = protocol(req) + "://" + req.get('host')
|
2018-07-12 15:14:45 +02:00
|
|
|
.replace(/(api|cufs|uonetplus|uonetplus-opiekun|uonetplus-uzytkownik)\./, "");
|
2017-12-04 20:58:22 +01:00
|
|
|
next();
|
|
|
|
});
|
|
|
|
|
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));
|
2018-12-11 20:35:50 +01:00
|
|
|
app.use(subdomain('uonetplus-opiekun', uonetplusOpiekun.use('/Default/123456', uonetplusOpiekun)));
|
|
|
|
app.use(subdomain('uonetplus-opiekun', uonetplusOpiekun.use('/Default/123457', uonetplusOpiekun)));
|
|
|
|
app.use(subdomain('uonetplus-opiekun', uonetplusOpiekun.use('/Default/123458', uonetplusOpiekun)));
|
2018-12-05 01:07:20 +01:00
|
|
|
app.use(subdomain('uonetplus-uczen', uonetplusUczen.use('/Default/123456', uonetplusUczen)));
|
2018-12-11 20:35:50 +01:00
|
|
|
app.use(subdomain('uonetplus-uczen', uonetplusUczen.use('/Default/123457', uonetplusUczen)));
|
|
|
|
app.use(subdomain('uonetplus-uczen', uonetplusUczen.use('/Default/123458', uonetplusUczen)));
|
2019-01-13 17:38:09 +01:00
|
|
|
app.use(subdomain('uonetplus-uzytkownik', uonetplusUzytkownik.use('/Default', uonetplusUzytkownik)));
|
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;
|