-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
52 lines (40 loc) · 1.49 KB
/
server.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
var http = require('http');
var bodyParser = require('body-parser');
var express = require('express');
var analyzer = require('./analyzer');
var stats = require('./stats')
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.post('/analyze', function(req, res) {
var text = req.body.toAnalyze;
var bigramResult = analyzer.analyze(text);
var statsResult = stats.getStats(text);
var result = {
"bigramResult": bigramResult,
"statsResult": statsResult
}
res.type('json');
res.send(JSON.stringify(result));
});
app.get('/prompt', function(req, res) {
var difficulty = req.query.difficulty;
var prompt;
if (difficulty == "easy") {
prompt = "Compare your home, village or city to the place you live at now. Describe things that are the same and different."
} else if (difficulty == "intermediate") {
prompt = "Do you think it is important for people to continue to travel into space? Why or why not? You may want to think about issues, such as: costs, dangers, rewards."
} else {
prompt = "Have North Americans become too dependent on the automobile for travel?"
}
res.type('text');
res.send(prompt);
});
// var port = process.env.PORT || 5000;
app.use(express.static('./public'));
http.createServer(app).listen(process.env.PORT || 5000, function(){
console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
});
// console.log('Server started on localhost:' + port);