-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
160 lines (115 loc) · 4.31 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
var express = require('express'),
path = require('path'),
consolidate = require('consolidate');
var isDev = process.env.NODE_ENV !== 'production';
var app = express();
var port = 3000;
app.use(express.static('data'));
app.use(express.static('client'));
app.use(express.static('client/page1/lib'));
app.engine('html', consolidate.ejs);
app.set('view engine', 'html');
app.set('views', path.resolve(__dirname, './server/views'));
// local variables for all views
app.locals.env = process.env.NODE_ENV || 'dev';
app.locals.reload = true;
var fs = require('fs')
app.use(require('body-parser').urlencoded({limit: '5mb', extended: true}));
let tsnejs = require('./server/routes/TSNE/tsnemanager.js');
let MI = require('./server/routes/erroranalysis/MoranI.js');
app.post("/",function(req, res, next) {
// parseReqJson(req.body, res, client);
// let time = new Date()
console.log(req.body.reqType)
if(req.body.reqType=="tsne"){
tsnejs.runtsne(req, res, next)
}if(req.body.reqType=="MoranI"){
MI.CalcLMI(req, res, next)
}if(req.body.reqType=="write"){
let w_data = new Buffer(req.body.data);
fs.writeFile(__dirname + '/test2.txt', w_data, {flag: 'a'}, function (err) {
if(err) {
console.error(err);
} else {
console.log('end');
}
});
let resj = JSON.stringify("done");
res.send(resj);
}if(req.body.reqType=="writeevent"){
let w_data = new Buffer(req.body.data);
fs.writeFile(__dirname + '/Ccrimeeventdata.txt', w_data, {flag: 'a'}, function (err) {
if(err) {
console.error(err);
} else {
console.log('end');
}
});
}
// console.log((new Date()).getTime()-time.getTime())
});
if (isDev) {
// static assets served by webpack-dev-middleware & webpack-hot-middleware for development
var webpack = require('webpack'),
webpackDevMiddleware = require('webpack-dev-middleware'),
webpackHotMiddleware = require('webpack-hot-middleware'),
webpackDevConfig = require('./webpack.config.js');
var compiler = webpack(webpackDevConfig);
// attach to the compiler & the server
app.use(webpackDevMiddleware(compiler, {
// public path should be the same with webpack config
publicPath: webpackDevConfig.output.publicPath,
noInfo: true,
stats: {
colors: true
}
}));
app.use(webpackHotMiddleware(compiler));
require('./server/routes')(app);
// add "reload" to express, see: https://www.npmjs.com/package/reload
var reload = require('reload');
var http = require('http');
var server = http.createServer(app);
reload(server, app);
server.listen(8000, function(){
console.log('App (dev) is now running on port 8000!');
});
} else {
// static assets served by express.static() for production
app.use(express.static(path.join(__dirname, 'public')));
require('./server/routes')(app);
app.listen(port, function () {
console.log('App (production) is now running on port 3000!');
});
}
// let express = require('express');
// let app = express();
// let http = require('http');
// let path = require('path');
// let util = require('util');
// let bodyParser = require('body-parser');
// let multer = require('multer');
// let client = require('./database/connect')
// let db = require('./database/querydb.js');
// let readText = require('./database/readtxt')
// app.use(express.static('./public'));
// app.use(express.static('./database'));
// app.use(express.static('./build'))
// app.use(require('body-parser').urlencoded({limit: '5mb', extended: true}));
// app.get('/', function(req, res) {
// res.sendFile("index.html");
// });
// function parseReqJson(json, res, client) {
// if (json.reqType === 'queryPoiByTraj') {
// db.readText(res);
// } else if (json.reqType === 'queryDb') {
// db.query(res, client, json);
// } else if (json.reqType === 'readText') {
// readText.readText(res, json.fileName, json.begin, json.readLineLimit);
// }
// }
// let server = app.listen(3001, function () {
// let host = server.address().address;
// let port = server.address().port;
// console.log('My web is listening at http://%s:%s', host, port);
// });