-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
38 lines (30 loc) · 1.04 KB
/
script.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
const express = require("express");
const bodyParser = require('body-parser');
const auth = require('./routers/authentication');
const mongoose = require('mongoose');
const cookieParser = require('cookie-parser');
const dataUrl = 'mongodb+srv://imrane:[email protected]/?retryWrites=true&w=majority&appName=imrane';
const {checkUser} = require('./routers/checkAuthentication');
const route = require("./routers/Routes")
const app = express();
const port = 8080;
//view engine
app.set("view engine", "ejs");
// Middleware
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cookieParser());
//connect to mongoDb
mongoose.connect(dataUrl)
.then(() => console.log('MongoDB connected'))
.then(app.listen(port, ()=> console.log(`the app runing in port ${port}`)))
.catch(err => console.log(err));
//routes
app.get("*", checkUser);
app.use("/", auth);
app.use("/", route);
// 404 Error Handler
app.use((req, res) => {
res.status(404).render("404");
});