-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
53 lines (41 loc) · 1.25 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//? config environment variable
require('dotenv').config({ path: './.env.dev' });
//? config express
const express = require('express');
const app = express();
const cors = require("cors");
//? development logging
const morgan = require('morgan');
if (process.env.NODE_ENV === 'development') app.use(morgan('dev'));
//? config connction database
require('./config/db').connect();
const workers = require('./workers');
const walletAddressRoutes = require('./routes/walletAddressRoutes');
const errorController = require('./controllers/errorController');
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use('/api/v1/wallets', walletAddressRoutes);
app.use(
morgan("dev", {
skip: function (req, res) {
return res.statusCode < 400;
},
})
);
//? dont access not defined routes
app.all('*', (req, res, next) => {
res.status(404)
.json({
status: 'fail',
message: `The ${req.originalUrl} can not find on this server!`
});
});
//? initial server running
const port = process.env.PORT || 3000;
const server = app.listen(port, () => {
console.log(`App runnig on port ${port}...`);
});
//? run worker
workers.runWorker();
app.use(errorController);