-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
40 lines (32 loc) · 1.15 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
const http = require('http');
const path = require('path');
const express = require('express');
const log = console.log;
const { preprocess_text, summarize } = require('./server/summarizer/summarizer');
const app = express();
const PORT = process.env.PORT || 4321;
const MODE = process.env.NODE_ENV || 'development';
// middlewares
app.use(express.json()); // parse incoming json message
app.use(express.static(path.join(__dirname, MODE === 'development' ? '/client' : '/dist'))); //serve static assets
// routes
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, MODE === 'development' ? '../client/index.html' : '../dist/index.html'));
});
app.post('/post', (req, res) => {
const {contractType, contractText} = req.body;
/* Ignore <contractType> for prototyping purpose */
preprocess_text(contractText)
.then( // Mock preprocess text
preprocessed => summarize(preprocessed)
)
.then (summarized => {
// log(summarized);
res.json(summarized)
})
.catch(err => {
log(err)
res.status(500).json({error: err})
})
})
app.listen(PORT, () => { console.log(`Server is up and running. Access: http://localhost:${PORT}`); });