-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
42 lines (31 loc) · 1.13 KB
/
server.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
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const path = require('path');
if (process.env.NODE_ENV !== "production") require('dotenv').config();
// Create express server instance
const app = express();
const port = process.env.PORT || 5000;
// Middleware for processing request body content
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cors());
if (process.env.NODE_ENV === "production") {
app.use(express.static(path.join(__dirname, "client/build")));
app.get("*", function (request, response) {
response.sendFile(path.join(__dirname, "client/build", "index.html"));
});
}
const accountRoutes = require("./routes/accounts");
app.use('/api/v1/accounts', accountRoutes)
const businessRoutes = require("./routes/businesses");
app.use('/api/v1/businesses', businessRoutes);
const loginRoute = require("./routes/login");
app.use('/login', loginRoute)
app.listen(port, error => {
if (error) throw error;
console.log("Server running on port " + port);
});
app.get("/", (req, res) => {
res.status(200).send("connected")
});