-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (39 loc) · 1.28 KB
/
index.js
File metadata and controls
47 lines (39 loc) · 1.28 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
44
45
46
47
const express = require('express');
const app = express();
const path = require("path");
const cors = require("cors");
const connectDB = require('./config/db');
//connection to mongoDB
connectDB();
//use cors
app.use(cors());
//use json encode
app.use(express.json({ extended: false }));
//routes
//user routes
app.use('/api/users/', require('./routes/users'));
app.use('/api/auth/', require('./routes/auth'));
//news and contact form
app.use('/api/news', require('./routes/news'));
app.use('/api/contact', require('./routes/contactForm'));
//hack routes
app.use('/api/hack/tasks', require("./routes/Hackaton/Tasks"));
app.use('/api/hack/teams', require("./routes/Hackaton/team"));
app.use('/api/hack', require('./routes/Hackaton/hack'));
//resolve static folder for react app
app.use(express.static("front-hack/build"));
app.get("*", (req,res) => {
res.sendFile(path.resolve(__dirname, 'front-hack', 'build', 'index.html'));
});
//initial port to start
const PORT = process.env.PORT || 5000;
//server app
app.listen(PORT, () => console.log(`Server is running on ${PORT}`));
/*
if (process.env.NODE_ENV === "production") {
app.use(express.static("front-app/build"));
app.get("*", (req,res) => {
res.sendFile(path.resolve(__dirname, 'front-app', 'build', 'index.html'));
});
}
*/