-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathapp.js
More file actions
69 lines (52 loc) · 1.92 KB
/
app.js
File metadata and controls
69 lines (52 loc) · 1.92 KB
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
60
61
62
63
64
65
66
67
68
var express = require('express');
var app = express();
//var url = require("url");
var path = require('path');
var logger = require('morgan');
var bodyParser = require('body-parser');
// const swaggerUi = require('swagger-ui-express');
// const swaggerDocument = require('./apidocs/swagger.json');
// app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
var rt_index = require('./routes/index');
var rt_order = require('./routes/order');
var rt_product = require('./routes/product');
var rt_customer = require('./routes/customer');
// Wiring up middleware, this must be before calling any routes
// https://expressjs.com/en/guide/writing-middleware.html
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
// Defining routes
app.use('/', rt_index);
app.use('/v1/order', rt_order);
app.use('/v1/product', rt_product);
app.use('/v1/customer', rt_customer);
// Wiring up error handler middleware, this must be after the routes
// catch 404 and forward to error handler
app.use( (req, res, next) => {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handler
app.use( (err, req, res, next) => {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
res.status(err.status || 500);
res.send('You Got Error');
});
var port = process.env.PORT || 3000;
console.log("Static Page:");
console.log(`http://localhost:${port}/`);
console.log();
console.log("API Access:");
console.log(`http://localhost:${port}/v1/order`);
console.log(`http://localhost:${port}/v1/product`);
console.log(`http://localhost:${port}/v1/order`);
console.log();
// console.log(`http://localhost:${port}/api-docs`);
// console.log();
//module.exports = app;
app.listen(port);