-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
22 lines (18 loc) · 1 KB
/
server.js
File metadata and controls
22 lines (18 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
let express = require('express') // "framework" node js to easily implement web server
const Indexor = require('./modules/indexor')
let app = express() // initialize of express, option may be passed, basic for now
//hbs.registerPartials(__dirname + '/views/partials') // indicate where are stored the part of hbs template
//app.set('view engine', 'hbs') // tell express that we use hbs for templating
app.use(express.static(__dirname + '/public')) // tell express where is the folder that will be access by users
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.get('/search/:q', (request, response) => {
let indexor = new Indexor('data/fact.json', ["content", "author", "date", "authenticity", "title"], false)
response.send(indexor.query(request.params.q))
})
let listener = app.listen(4000, () => {
console.log('server is running on: ', listener.address().port)
})