forked from yuktagopalani/Software-Engineering-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
121 lines (92 loc) · 2.85 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const express = require("express");
const app = express();
const path = require("path");
const mongoose = require("mongoose");
const methodOverride = require("method-override");
const bodyParser = require("body-parser");
const flash = require("connect-flash");
const passport = require("passport");
const LocalStrategy = require("passport-local");
const { session } = require("passport");
const upload = require("./utils/multer");
const {cloudinary} = require("./utils/cloudinary");
const { all } = require('async')
const User = require("./models/user");
const Video = require("./models/video");
// const fs=require("fs");
const userRoutes = require("./routes/users");
const { isLoggedIn } = require("./middleware/usermiddleware");
require('dotenv').config();
//PASSPORT CONFIGURATION
app.use(
require("express-session")({
secret: "Stay secured",
resave: false,
saveUninitialized: false,
})
);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(flash());
app.use(express.json());
app.use(express.urlencoded({extended: false}));
app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
app.use((req,res,next) => {
res.locals.currentUser = req.user;
res.locals.error = req.flash("error");
res.locals.success = req.flash("success");
next();
});
mongoose.set('useUnifiedTopology', true);
const url = process.env.MONGODB_URI || 8000
mongoose.connect(url, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true,
useFindAndModify: false
}, () => {
console.log("Connected to database.");
});
app.set("view engine", "ejs");
app.use(express.static(__dirname + "/public"));
app.use('/', userRoutes);
app.get("/", (req, res) => {
res.render("home");
});
app.get("/about", (req, res) => {
res.render("about");
});
app.get("/record",(req, res) => {
res.render("recorder");
});
app.get("/error", (req, res) => {
res.render("errormsg");
});
app.get("/videos",async(req,res) =>{
const all_file = await cloudinary.api.resources();
const files = await all_file.resources;
res.render('profile', {files});
});
app.get("/newVid", (req,res) =>{
res.render("newVid");
});
app.post("/videos", upload.single('file') , async (req,res) =>{
const result = await cloudinary.uploader.upload(req.file.path, {resource_type: 'auto'});
console.log("result: ", result);
// const post_details = {
// title: req.body.title,
// image: result.public_id
// }
//res.status(200).json({post_details});
res.redirect('/videos');
});
app.get("/track", (req,res) =>{
res.render("track");
});
let port = process.env.PORT || 8000
app.listen(port, process.env.IP, () => {
console.log("showing on port 8000.");
});