-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
39 lines (27 loc) · 934 Bytes
/
app.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
// Node dependencies
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const morgan = require("morgan");
// Import models
const ApiResponse = require('./models/ApiResponse');
// Import routes
const test_routes = require('./routes/test_routes');
const plug_routes = require('./routes/plug_routes');
const app = express();
// Parse the request body to JSON
app.use(bodyParser.json());
// Setup Morgan as Logger
app.use(morgan("dev"));
// Enable CORS-support
app.use(cors());
app.get('/', function(req, res, next) {
res.status(200).send(new ApiResponse("Hello World!", 202));
});
app.use('/api', test_routes);
app.use('/api', plug_routes);
//This endpoint is called when no other one was found, and throws a 404 error
app.use('*', function(req, res, next){
res.status(404).send(new ApiResponse("This endpoint doesnt't exist", 404));
});
module.exports = app;