-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (32 loc) · 1.2 KB
/
server.js
File metadata and controls
43 lines (32 loc) · 1.2 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
const path = require("path");
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const cors = require("cors");
const colors = require("colors");
const mongooseURI = require("./config/keys").mongoURI;
const userRoutes = require("./routes/user");
const shopRoutes = require("./routes/shop");
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use("/images", express.static(path.join(__dirname, "images")));
app.use(express.static(process.cwd()+"/client/dist/client/"));
app.get('/', (req,res) => {
res.sendFile(process.cwd()+"/client/dist/client/index.html")
})
app.use("/api/user", userRoutes);
app.use("/api/shop", shopRoutes);
mongoose
.connect(mongooseURI)
.then(() => {
const port = process.env.PORT || 5000;
const server = app.listen(port, () => {
console.log("Server running on port".magenta, colors.yellow(port));
});
console.log("\nConnected to".magenta, "E-MART".cyan, "database".magenta);
})
.catch(err => console.log("Error connecting to database".cyan, err));