This repository has been archived by the owner on Sep 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
106 lines (97 loc) · 2.22 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
/// website controll panel
// requires
const express = require("express");
const mongoose = require("mongoose");
const livereload = require("livereload");
const connectLivereload = require("connect-livereload");
const path = require("path");
const Storys = require("./models/storysSchema");
const About = require("./models/aboutSchema");
const { isAbsolute } = require("path");
// express sittings
const app = express();
const port = 5000;
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(express.static("public/images"));
app.use(
express.urlencoded({
extended: true
})
);
// for auto refresh in localhost
const liveReloadServer = livereload.createServer();
liveReloadServer.watch(path.join(__dirname, "public"));
app.use(connectLivereload());
liveReloadServer.server.once("connection", () => {
setTimeout(() => {
liveReloadServer.refresh("/");
}, 100);
});
// mongoose sittings
const dbname = "church";
const db = `proccess.env.DB`;
mongoose
.connect(db)
.then(result => {
// express
app.listen(process.env.PORT || port, () => {
console.log(`Knisty App is listening at http://localhost:${port}`);
});
})
.catch(err => {
console.log(err);
});
/// pages
// HOME
app.get("/", (req, res) => {
res.render("home", {
mytitle: "قصص الاباء البطاركة كاملة"
});
});
// ABOUT
app.get("/about-me", (req, res) => {
About.find()
.then(result => {
res.render("about", {
mytitle: "About Me",
arrAbout: result
});
})
.catch(err => {
console.log(err);
});
});
// STORYS
app.get("/storys", (req, res) => {
Storys.find()
.then(result => {
res.render("storys-control-panel", {
mytitle: "جميع القصص",
arrStory: result
});
})
.catch(err => {
console.log(err);
});
});
// DYNAMIC STORYS LINK
app.get("/storys/:id", (req, res) => {
const id = req.params.id;
Storys.findById(id)
.then(result => {
res.render("story", {
mytitle: result.title,
arrStory: result
});
})
.catch(err => {
console.log(err);
});
});
// 404 page
app.use((req, res) => {
res.status(404).render("404", {
mytitle: "404 page not found"
});
});