-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
33 lines (27 loc) · 831 Bytes
/
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
import Server from 'socket.io';
import express from 'express';
import gingerbread from 'gingerbread';
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/dist'));
server.listen(app.get('port'));
var globalState = [];
io.on('connection', (socket) => {
socket.emit('state', globalState);
});
app.get('/api', (req, res) => {
console.log('got a request!', req.query.sentence);
gingerbread(req.query.sentence, function (error, text, result, corrections) {
let correction = {
error: error,
text: text,
result: result,
corrections: corrections
};
globalState.push(correction);
io.emit('state', globalState);
res.json(correction);
})
});