-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
138 lines (121 loc) · 4.09 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const express = require('express');
const path = require('path');
//var favicon = require('serve-favicon');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const session = require('client-sessions');
const index = require('./routes/index');
const analysis = require('./routes/analysis');
const profile = require('./routes/profile');
const signin = require('./routes/signin');
const signup = require('./routes/signup');
const test = require('./routes/test');
const loadtext = require('./routes/loadtext');
const setup = require('./routes/setup');
const comment = require('./routes/comment');
const imprint = require('./routes/imprint');
const expressVue = require('express-vue');
const ip = require('ip');
const app = express();
const ipAdress = ip.address();
const dbStub = require('./modules/db_stub');
dbStub.fiberEstablishConnection();
if (process.env.NODE_ENV === 'production') {
//its production so use the minimised production build of vuejs
vueScript = 'https://unpkg.com/vue';
}
const vueOptions = {
rootPath: path.join(__dirname, '/views'),
layout: {
html: {
start: '<!DOCTYPE html><html>',
end: '</html>'
},
body: {
start: '<body>',
end: '</body>'
},
template: {
start: '<div id="app">',
end: '</div>'
}
},
vue: {
head: {
title: 'NLA - Natural Language Analyse Tool',
meta: [
{script: '/javascripts/vue.js'},
{script: 'https://code.getmdl.io/1.3.0/material.min.js'},
{style: 'https://code.getmdl.io/1.3.0/material.indigo-blue.min.css'},
{style: 'https://fonts.googleapis.com/icon?family=Material+Icons'},
{style: 'https://cdnjs.cloudflare.com/ajax/libs/simple-line-icons/2.4.1/css/simple-line-icons.css'},
{style: '/css/style.css'},
{charset: 'UTF-8'}
]
}
},
data: {
title:'NLA - Natural Language Analyse Tool',
title_small: 'NLA - Tool',
serverip: ipAdress
}
};
const expressVueMiddleware = expressVue.init(vueOptions);
app.use(expressVueMiddleware);
app.use(session({
cookieName: 'session',
secret: 'jierjfijeifjiedffakopkerrtjfswf0j',
duration: 30 * 60 * 1000,
activeDuration: 5 * 60 * 1000,
}));
// view engine setup
//app.set('views', path.join(__dirname, '/views'));
app.set('view engine', 'vue');
// 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')));
app.use('/', index);
app.use('/analysis', analysis);
app.use('/signin', signin);
app.use('/profile', profile);
app.use('/signup', signup);
app.use('/test', test);
app.use('/loadtext', loadtext);
app.use('/setup', setup);
app.use('/comment', comment);
app.use('/imprint', imprint);
// catch 404 and forward to connectionError handler
app.use(function (req, res, next) {
let err = new Error('Not Found');
err.status = 404;
next(err);
});
// connectionError handler
app.use(function (err, req, res, next) {
// set locals, only providing connectionError in development
res.locals.message = err.message;
res.locals.connectionError = req.app.get('env') === 'development' ? err : {};
// render the connectionError page
console.log(err);
res.status(err.status || 500);
const data = {
message: err.message,
error: err,
status: err.status,
stack: err.stack
};
res.renderVue('error', data);
});
app.set('port', process.env.PORT || 3000);
let server = app.listen(app.get('port'), function () {
var ipVerson = "ipV4";
if (server.address().address == "::")
ipVerson = "ipV6";
console.log('Express server listening on ' + ipVerson + ' http://' + server.address().address + ":" + server.address().port);
});
module.exports = app;