-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
108 lines (84 loc) · 2.92 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
const express = require("express");
const path = require("path");
const Port = 5000;
const bodyParser = require("body-parser");
const session = require("express-session");
const mongoose = require("mongoose");
const passport = require("./middleware/auth");
require("dotenv").config();
// router start landing page
const cartRoute = require("./routes/cartRoute");
const indexRoute = require("./routes/indexRoute");
const serviceRoute = require("./routes/serviceRoute");
const signinRoute = require("./routes/signinRoute");
const signupconstumerRouter = require("./routes/signupconsumerRouter");
const signupfarmerRouter = require("./routes/signupfarmerRoute");
// router for admin
const indexao = require("./routes/AgriOffice/indexRouter");
const registAdmin = require("./routes/AgriOffice/registerAdminRouter");
const registFarmOne = require("./routes/AgriOffice/registerFarmo");
// farmone route
const indexFO = require("./routes/farmone/indexRoute");
// router for urbanFarmer
const adding = require("./routes/urbanfarmer/addingRoute");
const indexuf = require("./routes/urbanfarmer/indexRoute");
// router stop
const app = express();
app.use(session({
secret: "secret",
resave: false,
saveUninitialized: false,
}));
app.use(passport.authenticate('session'));
// Configure passport middleware
app.use(passport.initialize());
app.use(passport.session());
app.use((req, res, next) => {
console.log(`${req.method} ${req.baseUrl}${req.url}`);
next();
});
// use a middle for public folder
app.use(express.static("public"));
// support parsing of application/json type post data
app.use(bodyParser.json());
//support parsing of application/x-www-form-urlencoded post data
app.use(bodyParser.urlencoded({ extended: true }));
// require("dotenv").config();
const config = require("./config/database");
//starting to add database
//creating a connection between the controller and the database
mongoose.connect('mongodb+srv://sarahndianekwu:[email protected]/?retryWrites=true&w=majority', {
useNewUrlParser: true,
useUnifiedTopology: true,
});
const db = mongoose.connection;
//checking for the err in the mongodb
db.on('error', console.error.bind(console, 'connection error:'));
// checking if database has connected
db.once("open", () => {
console.log("connected to db");
});
app.set("view engine", "pug");
app.set("views", path.join(__dirname, "views"));
app.set("views", path.join(__dirname, "views", "page"));
app.use(cartRoute);
app.use(indexRoute);
app.use(serviceRoute);
app.use(signinRoute);
app.use(signupconstumerRouter);
app.use(signupfarmerRouter);
// app use for agriculture office
app.use(indexao);
app.use(registAdmin);
app.use(registFarmOne);
// app use for farmone
app.use(indexFO);
// app use for urbanfarmers
app.use(adding);
app.use(indexuf);
app.get("*", (req, res) => {
res.status(404).send("page does not exist");
});
app.listen(process.env.port || Port, () => {
console.log(`listen to port ${Port}`);
});