-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
105 lines (76 loc) · 2.36 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
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
const express =require('express');
const session = require('express-session');
const app = express();
const port = 8001;
const passport= require('passport')
const ejs= require('ejs');
const path =require('path');
const check =require('./utils/jwt')
const cookieParser = require('cookie-parser');
app.use(express.json());
require('./config/passport')(passport);
app.use(express.static(__dirname + '/public'))
const cors = require('cors');
const corsOptions = {
"origin": "*",
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
"preflightContinue": false,
"optionsSuccessStatus": 204
}
app.use(cors(corsOptions))
app.use(
session({
secret: process.env.SECRET, // Change this to a secure random string
resave: false,
saveUninitialized: true,
})
);
app.use(passport.initialize());
app.use(passport.session());
app.use(cookieParser());
app.use(express.urlencoded({ extended: true }));
const template_path = path.join(__dirname, "./views");
app.set("view engine", "ejs");
app.set("views", template_path);
const router = require('./routes/user')
const router2 = require('./routes/file')
const router3 =require('./routes/display')
const router4 =require('./routes/download')
app.use('/api/',router);
app.use('/api/',router2);
app.use('/files',router3);
app.use('/files/download',router4)
app.get('/',async(req,res)=>{
console.log(req.session.username);
await res.render('upload')
})
app.get('/auth',
passport.authenticate('google', { scope: ['profile', 'email'],
includeGrantedScopes: true,
prompt: 'select_account'}));
app.get('/auth/callback',
passport.authenticate('google', { failureRedirect: '/login' }),
function(req, res) {
// Successful authentication, redirect home.
console.log(req.user);
res.redirect('/');
});
app.get('/log',(req,res)=>{
res.render('logout.ejs');
})
// app.get('/dashboard', (req, res) => {
// // Check if the user is authenticated
// // Pass user details to the dashboard template
// res.render('home.ejs', { user: req.user });
// });
app.get("/login", (req, res) => {
res.render("login.ejs");
})
app.get("/sig", (req, res) => {
res.render("signup.ejs");
})
const File= require('./model/file');
const person= require('./model/person');
const connectToDatabase=require('./config/db');
connectToDatabase();
app.listen(port,()=>{ console.log(`srever is connected and running on ${port}`)})