-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
71 lines (58 loc) · 2.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const express = require('express');
const mongoose = require('mongoose');
const logger = require("morgan");
const path = require("path");
const cookieParser = require("cookie-parser");
const cors = require("cors");
const bodyParser = require('body-parser');
const app = express();
const port = process.env.PORT || 8080;
require('dotenv/config');
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));
app.use(cors());
// console.log that your server is up and running
app.listen(port, () => console.log(`Listening on port ${port}`));
//Middleware to accept Body
app.use(bodyParser.json() );
//Region Start - Routing for Sign Up
const signUp = require('./routes/api/signUp');
app.use('/signup', signUp);
//Region End - Routing for Sign Up
//Region Start - Routing for Sign Up
const login = require('./routes/api/login');
app.use('/login', login);
//Region End - Routing for Sign Up
//Region Start - Routing for Post
const post = require('./routes/api/post');
app.use('/post', post);
//Region End - Routing for Post
//Region Start - Routing for Sign Up
const user = require('./routes/api/user');
app.use('/user', user);
//Region End - Routing for Sign Up
//Region Start - Upload Images Middleware
app.use('/uploads',express.static('uploads'));
// Example: http://localhost:5000/uploads/2020-04-05T15:34:54.325ZTest-Image.png
//Region End - Upload Images Middleware
//Region Start - Routing for Homepage
const home = require('./routes/api/home');
app.use('/', home);
// Region End - Routing for Homepage
// Connecting to MongoDB
// Handles local database and live database.
if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'development') {
mongoose.connect(process.env.DB_CONNECTION_LIVE,
{ useNewUrlParser: true },
() => console.log("Connected to DB"))
} else if (process.env.NODE_ENV === 'local') {
mongoose.connect(process.env.DB_CONNECTION_TEST,
{ useNewUrlParser: true },
() => console.log("Connected to DB"))
};
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
};