-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (47 loc) · 1.33 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
import express from "express";
import { dirname } from "path";
import { fileURLToPath } from "url";
import bodyParser from "body-parser";
const app = express();
const port = 3000;
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("public"));;
const __dirname = dirname(fileURLToPath(import.meta.url));
app.get("/",(req,res)=>{
res.sendFile(__dirname + "/public/index.html");
})
app.get("/create", (req, res) => {
res.render(__dirname + "/view/create.ejs");
});
app.get("/contact", (req, res) => {
res.render(__dirname + "/view/contact.ejs");
});
app.get("/openBlog1",(req,res)=>{
res.render(__dirname+"/view/blog1.ejs");
});
app.get("/openBlog2",(req,res)=>{
res.render(__dirname+"/view/blog2.ejs");
});
app.get("/openBlog3",(req,res)=>{
res.render(__dirname+"/view/blog3.ejs");
});
app.get("/openBlog4",(req,res)=>{
res.render(__dirname+"/view/blog4.ejs");
});
app.post("/post",(req,res)=>{
const blogTitle=req.body.title;
const blogContent=req.body.content;
console.log(blogTitle);
console.log(blogContent);
res.render(__dirname + "/view/newBlog.ejs",{
titleOfBlog:blogTitle,
contentOfBlog:blogContent
});
});
app.post("/submit", (req, res) => {
res.send('Submitted Successfully!');
res.redirect('/');
});
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});