-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
58 lines (44 loc) · 1.6 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
54
55
56
57
58
const express = require('express')
const bodyParser = require("body-parser");
const {json} = require('express');
const cors = require('cors');
const app = express();
const port = 4000
//const authJwt = require('./helpers/jwt');
const morgan = require('morgan');
const mongoose = require('mongoose');
require('dotenv/config');
// Initialization CORS
app.use(cors());
app.options('*', cors)
//middleware
app.use(bodyParser.json());
app.use(morgan('tiny'))
//app.use(authJwt);
app.use('public/upload', express.static(__dirname + 'public/upload'))
//app.use(errorHanlder);
//routes
const categoriesRoutes =require('./routes/categories');
const productsRoutes =require('./routes/products');
const usersRoutes =require('./routes/users');
const ordersRoutes =require('./routes/orders');
const api = process.env.API_URL;
app.use(`${api}/categories`, categoriesRoutes);
app.use(`${api}/products`, productsRoutes);
app.use(`${api}/users`, usersRoutes);
app.use(`${api}/orders`, ordersRoutes);
//Database
mongoose.connect(process.env.CONNECTION_STRING, {
useNewUrlParser: true,
dbName: 'eshop-database1'
})
.then(() => {
console.log('Database Connection is ready...')
})
.catch((err) => {
console.log(err);
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
console.log(api)
})