-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
66 lines (49 loc) · 1.74 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
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const cors = require('cors');
const session = require('express-session');
require('dotenv').config()
const port = process.env.PORT || 4000
//Importing routs
const deleteRoute = require('./routes/delete');
const logoutRoute = require('./routes/logout');
const loginRoute = require('./routes/login');
const registerRoute = require('./routes/register');
const profileRoute = require('./routes/profile');
//Setting up server
const corsOptions = {
hostname: 'https://web3-registration-fe.pages.dev/',
optionsSuccessStatus: 200, // For legacy browser support
methods: "GET, PUT, POST"
}
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(express.static("public"));
app.use(cors(corsOptions))
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
app.use(session({
secret: process.env.SECRETKEY,
resave: false,
saveUninitialized: true,
}));
//Mongoose connection
mongoose.set('strictQuery', false);
mongoose.connect("mongodb+srv://"+process.env.USERDB+":"+process.env.PASSDB+"@socialapp.ds4zn.mongodb.net/UsersDB", { useNewUrlParser: true })
app.route("/")
.get((req,res) => {
res.send("Web 3 Registration Back End")
});
//Routs
app.use("/login" ,loginRoute)
app.use("/register" ,registerRoute)
app.use("/profile" ,profileRoute)
app.use("/logout" ,logoutRoute)
app.use("/delete" ,deleteRoute)
//Port
app.listen(port, () => console.log(`Server is running on port ${port}.`));