-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
124 lines (91 loc) · 3.15 KB
/
index.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
var createError = require('http-errors');
const cors = require("cors");
var bodyParser = require('body-parser');
var express = require('express');
var path = require('path');
// var cookieParser = require('cookie-parser');
var logger = require('morgan');
// var indexRouter = require('./routes/api/index');
var signUp = require('./routes/api/signup');
var login = require('./routes/api/login');
var item = require("./routes/api/item")
// var user = require('./routes/api/users')
// var campaign = require('./routes/api/campaign')
// var admin = require('./routes/api/admin')
const mongoose = require("mongoose");
var app = express();
// view engine setup
// require('dotenv').config()
// app.engine('html', require('ejs').renderFile);
// app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'jade');
// if(process.env.NODE_ENV == "production"){
// app.use(express.static("client/build"))
// app.get("*", (req, res)=> {
// res.sendFile(path.resolve(__dirname, "client","build", "index.html"))
// })
// }
app.use(
cors({
// origin: ["http://localhost:3000", "http://127.0.0.1:3000"],
credentials: true
})
);
// app.use(logger('dev'));
app.use(express.json());
// app.use(bodyParser({limit: '50mb'}))
app.use(bodyParser.urlencoded({
extended: true,
limit : "50mb"
}));
// app.use(express.urlencoded({ extended: false }));
app.use(logger("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// app.use(cookieParser());
// app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'ejs');
// app.use(cookieParser());
// app.use(express.static(path.join(__dirname, 'public')));
// app.use((req, res, next) => {
// res.header('Access-Control-Allow-Origin', '*');
// next();
// });
// app.use('/', indexRouter);
app.use('/api/signup', signUp);
app.use('/api/login', login);
app.use('/api/items', item);
// app.use('/api/campaign', campaign)
// app.use("/api/admin", admin)
// mongoose uri
const db = "mongodb://joshayewah:[email protected]:27017,josh-shard-00-01-mly6u.mongodb.net:27017,josh-shard-00-02-mly6u.mongodb.net:27017/test?ssl=true&replicaSet=Josh-shard-0&authSource=admin&retryWrites=true&w=majority";
// Connect to mongoose
console.log(db)
mongoose
.connect(db,
{
useNewUrlParser : true,
useCreateIndex : true,
useUnifiedTopology: true,
useFindAndModify:false
})
.then(() => console.log("MongoDB Connected..."))
.catch(err => console.log(err));
// if (process.env.NODE_ENV === "production") {
// app.use(express.static("client/build"));
// app.get("*", (req, res) => {
// res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
// });
// }
// catch 404 and forward to error handler
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
}
app.set("port", process.env.PORT || 5200);
const server = app.listen(app.get("port"), () => {
console.log(`Express running → PORT ${server.address().port}`);
});
// module.exports = app;