-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
35 lines (27 loc) · 798 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
const express = require('express')
const app = express()
const medias = require('./medias');
const feedback = require('./feedback');
app.use(express.static('public'))
var bodyParser = require('body-parser')
var jsonParser = bodyParser.json();
app.get('/', function (req, res) {
res.send('Hello World')
})
//stack overflow
app.get('/medias/so/:id', async (req, res) => {
let d = await medias.getStackOverflowData(req.params.id);
res.setHeader('Content-Type', 'application/json');
res.send(d);
})
app.post('/feedback', jsonParser, async (req, res) => {
feedback.save(req.body).then(success => {
if (success) {
res.send('success');
} else {
res.send('error')
}
})
})
var port = process.env.PORT || 3000;
app.listen(port);