-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (38 loc) · 1.06 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
'use strict';
global.db = require('./dbconnect');
var express = require('express');
var bodyparser = require('body-parser');
var cors = require('cors');
// Constantes
var PORT = 5055;
var HOST = '127.0.0.1';
// App
var app = express();
// Implementa compartilhamento de recursos Cross-Origin
var corsOptions = {
origin: 'http://localhost',
optionsSuccessStatus: 200
};
var corsOptionsDelegate = function(req, callback){
callback(null, corsOptions); // callback expects two parameters: error and options
};
app.options('/kb', cors(corsOptionsDelegate));
// Implementa um parser
app.use(bodyparser.json());
app.get('/teste', function (req, res) {
res.send('search.bhsul esta vivo!\n');
});
//POST
app.post('/kb', cors(corsOptions), function(req, res) {
var param;
var resultado;
if (!req.body) return res.sendStatus(400);
param = req.body.consulta;
global.db.pesquisarKB(param, (e, list) => {
if (e) { return console.log(e); }
res.send(list);
});
});
app.listen(PORT);
console.log('Executando em http://localhost:' + PORT);
module.exports = app;