-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
59 lines (49 loc) · 1.84 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
53
54
55
56
57
58
59
const express = require('express');
const bodyParser = require('body-parser');
var cors = require('cors');
const fs = require('fs');
const app = express();
app.use(cors());
app.use(bodyParser.json({ limit: '50mb' }));
app.get('/', function(req, res) {
res.send('Silverlight Replace Backend Mock, version 0.0.1\n\n' + new Date());
});
app.get('/ping', function(req, res) {
res.send('success\n\n' + new Date());
});
app.get('/api/autocomplete', function(req, res) {
console.log('GET:' + '/api/recipes');
const response = JSON.parse(fs.readFileSync('responses/Result.json'));
console.log('Response: \n' + JSON.stringify(response));
res.send(response);
});
// app.get('/api/responses', function(req, res) {
// console.log('GET:' + '/api/responses');
// const response = JSON.parse(fs.readFileSync('responses/ResponsesWithoutFilter.json'));
// console.log('Response: \n' + JSON.stringify(response));
// res.send(response);
// });
app.post('/api/responses', function(req, res) {
console.log('POST:' + '/api/responses');
console.log(req.body)
if(req.body.filters.length>0){
const response = JSON.parse(fs.readFileSync('responses/ResponsesWithFilter.json'));
res.send(response);
}else{
if(req.body.searchquery === "computer")
{
const response = JSON.parse(fs.readFileSync('responses/ResponsesWithoutAutocorrect.json'));
res.send(response);
}
else{
const response = JSON.parse(fs.readFileSync('responses/ResponsesWithoutFilter.json'));
res.send(response);
}
}
});
const server = app.listen(20403, () => {
const host = server.address().address;
const port = server.address().port;
const headers = {"Access-Control-Allow-Origin": "*"};
console.log('Silverlight Replace Backend Mock listening at http://%s:%s', host, port, headers);
});