-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·53 lines (38 loc) · 1.53 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
const dotenv = require("dotenv").config();
const express = require ('express');
const app = express();
const port = process.env.port || 4000;
const connectDB = require ('./config/db');
const mongoose = require ('mongoose');
const bodyParser = require ('body-parser');
const cors = require('cors');
// =================== initial settings ===================
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
//Connect to Database
connectDB();
//============== CORS =========
app.use(cors());
// allowing requests from the front-end to our server with api calls
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
next();
});
// =============== ROUTES ==============================
const adminRoutes = require('./routes/AdminRoute');
const productRoutes = require('./routes/ProductRoute');
const cartRoutes = require('./routes/CartRoute');
const paymentRoute = require('./routes/PaymentRoute');
const emailRoute = require('./routes/EmailRoute');
// =============== USE ROUTES ============================
app.use('/', adminRoutes);
app.use('/', productRoutes);
app.use('/', cartRoutes);
app.use('/', paymentRoute);
app.use('/', emailRoute);
// =============== START SERVER =====================
app.listen (port, ()=>{
console.log(`server is running on port ${port}`)
});