-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
69 lines (57 loc) · 1.83 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
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const passport = require("passport");
require("dotenv").config();
require("custom-env").env();
require("custom-env").env("test");
require("./config/passport.js");
const authRoutes = require("./routes/auth.js");
const app = express();
const corsConfig = {
credentials: true,
origin: true,
};
app.use(cors(corsConfig));
/* allow localhost only */
// app.use(cors(
// {
// origin: 'http://localhost:8080',
// credentials: true }
// ));
//swagger dependencies
const swaggerUi = require("swagger-ui-express");
const yaml = require("yamljs");
//setup swagger
const swaggerDefinition = yaml.load("./swagger.yaml");
app.use("/api/swagger", swaggerUi.serve, swaggerUi.setup(swaggerDefinition));
// parse requests of content-type - application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));
// parse requests of content-type - application/json
app.use(bodyParser.json());
// app.use('/api/user', passport.authenticate('jwt', {session: false}), authRoutes)
app.use("/api/user", authRoutes);
// Hi route
app.get("/api/", (req, res) => {
res.json({ message: "Welcome to the Project Management Application" });
});
// set port, listen for requests
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}.`);
});
const db = require("./models");
db.mongoose
.connect(db.url, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("Connected to the database succesfully!");
})
.catch((err) => {
console.log("Cannot connect to the database!", err);
process.exit();
});
require("./routes/project.routes.js")(app, passport);
module.exports = app;