-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (58 loc) · 1.71 KB
/
app.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
import express from 'express';
// import { MongoClient } from 'mongodb';
import cors from 'cors';
import dotenv from 'dotenv';
import authRoutes from './routes/auth.routes.js';
import userRoutes from './routes/user.routes.js';
import dbManager from './database/index.js';
dotenv.config()
const app = express();
var corsOptions = {
origin: 'http://localhost:3000'
};
app.use(cors(corsOptions));
// parse requests of content-type - application/json
app.use(express.json());
// parse requests of content-type - application/x-www-form-urlencoded
app.use(express.urlencoded({ extended: true }));
app.use(function (req, res, next) {
res.header(
"Access-Control-Allow-Headers",
"x-access-token, Origin, Content-Type, Accept",
"x-access-refreshToken, Origin, Content-Type, Accept",
);
next();
});
dbManager.initDb().then((dbs) => {
app.get('/', (req, res) => {
res.json({ message: `API is up and running!` });
});
authRoutes.authRoutes(app, dbs);
userRoutes.userRoutes(app, dbs);
}).catch(console.dir);
/*
db.mongoose
.connect(`mongodb+srv://atlante_avila:${process.env.DBPASS}@cluster0.t8boi.mongodb.net/myFirstDatabase?retryWrites=true&w=majority`, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => {
console.log("Successfully connect to MongoDB.");
helpers.initial();
})
.catch(err => {
console.error("Connection error", err);
process.exit();
});
// simple route
app.get('/', (req, res) => {
res.json({ message: `API is up and running!` });
});
authRoutes.authRoutes(app);
userRoutes.userRoutes(app);
*/
// set port, listen for requests
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}.`);
});