-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
92 lines (71 loc) · 1.78 KB
/
index.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
import express from "express";
import bodyParser from "body-parser";
import ejs from "ejs";
const app = express();
const port=3000;
let raw_text = "";
let raw_content = "";
let raw_time_now = "";
let raw_short_post="";
let data={};
app.use(express.static("public"));
app.use(bodyParser.urlencoded({ extended: true }));
function input_text(req,res,next){
raw_text = req.body["title"];
raw_content = req.body["content"];
raw_short_post=req.body["short-post"];
raw_time_now = new Date().toLocaleString();
data={text:raw_text,content:raw_content,time_now:raw_time_now,short_post:raw_short_post};
next();
}
app.get("/create",(req,res)=>{
if(raw_text.length>0){
res.render("error.ejs");
}
else{
res.render("create.ejs");
}
})
app.get("/blogs",(req,res)=>{
res.render("blogs.ejs",data);
})
app.post("/submit",input_text,(req,res)=>{
res.render("post.ejs",
data);
})
app.get("/contact",(req,res)=>{
res.render("contact.ejs");
})
app.get("/post",(req,res)=>{
res.render("post.ejs",{text:raw_text , content:raw_content, time_now:raw_time_now});
})
app.get("/update",(req,res)=>{
if(raw_text.length<=0){
res.render("error2.ejs");
}
else{
res.render("update.ejs");
}
})
app.get("/reset",(req,res)=>{
raw_text="";
raw_content="";
raw_time_now="";
raw_short_post="";
data={};
res.render("index.ejs");
})
app.get("/delete",(req,res)=>{
if(raw_text.length<=0){
res.render("error2.ejs");
}
else{
res.render("delete.ejs");
}
})
app.get("/",(req,res)=>{
res.render("index.ejs");
})
app.listen(port,()=>{
console.log(`Server is running at port ${port}`);
})