-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (38 loc) · 955 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const express = require('express');
const { analyzeTasks } = require('./helpers/app');
const app = express();
const port = process.env.PORT || 8080;
//app.use(express.json());
app.use(express.text({
defaultCharset: "utf-8"
}));
app.use(express.urlencoded({
extended: true
}));
app.get('/', (req, res) => {
res.status(200).send({
success: true,
message: 'Welcome to Task Analyzer 👷🏽♀️'
});
});
app.post('/analyze/tasks', async (req, res) => {
try {
const output = analyzeTasks(req.body);
if(!output){
res.status(404).send({
success: false
});
}
res.status(200);
res.format({
'text/plain' : function(){
res.send(output);
}
});
} catch (error) {
res.status(500).send();
}
});
app.listen(port, () => {
console.log(`Listening on port ${port} 🌍`);
});