-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (36 loc) · 1013 Bytes
/
index.js
File metadata and controls
43 lines (36 loc) · 1013 Bytes
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
'use strict';
const express = require('express');
var cors = require('cors')
const app = express();
const bodyParser = require('body-parser');
const index = require('./routes/index');
const path = require('path');
const getUrl = require('./routes/getUrl');
const createQA = require('./routes/createQA');
const routes = [index, getUrl, createQA];
const PORT = process.env.PORT || 7080;
function errorHandler(err, req, res, next) {
if (err.isBoom) {
const error = err.output.payload;
res.status(error.statusCode || 500);
res.json({
message: error.message,
error: error.error
})
} else {
res.status(err.status || 500);
res.json({
message: err.message,
error: err
});
};
};
app.use(cors());
app.use(bodyParser.json());
app.use('/', routes);
app.use(express.static(path.join(__dirname, 'public')));
app.use(errorHandler);
const server = app.listen(PORT, function () {
console.log(`Example app listening on port ${PORT}!`)
});
module.exports = server;