-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (33 loc) · 1.13 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
const express = require("express");
const cors = require("cors");
const cookieParser = require("cookie-parser");
const usersRouter = require("./routes/users");
const productsRouter = require("./routes/products");
const orderRouter = require("./routes/orders");
const path= require("path");
const authenticationRouter = require("./routes/authentication");
const fileupload = require("express-fileupload")
const bodyParser = require("body-parser")
// Database Connection Object
const connect = require("./db/connection");
const app = express();
app.use(express.json());
app.use(cors());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use('/images', express.static( __dirname + '/uploads'))
app.use(fileupload());
//Route Configuration
app.use("/", authenticationRouter);
app.use("/users", usersRouter);
app.use("/products", productsRouter);
app.use("/orders", orderRouter);
//Handle Unknown Path
app.use((req, res, next) => {
res.status(404).send("Not found");
});
// error handler
app.use(function (err, req, res, next) {
res.status(err.status || 500).send(err.message || err);
});
module.exports = app;