forked from getgridea/gridea-theme-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·61 lines (52 loc) · 1.45 KB
/
app.js
File metadata and controls
executable file
·61 lines (52 loc) · 1.45 KB
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
const express = require("express");
const ejs = require("ejs");
const path = require("path");
const axios = require("axios");
const fs = require("fs");
const app = express();
app.use(express.static(__dirname));
app.set("views", path.join(__dirname, "/templates"));
app.set("view engine", "ejs");
/**
* Home Page & Post List Page
*/
app.get("/", async (req, res) => {
const data = fs.readFileSync("datas/list.json", "UTF8");
const response = JSON.parse(data.toString());
res.render("index", { ...response });
});
/**
* Post Page
*/
app.get("/post/:postName", async (req, res) => {
const data = fs.readFileSync("datas/post.json", "UTF8");
const response = JSON.parse(data.toString());
res.render("post", { ...response });
});
/**
* Archives Page
*/
app.get("/archives", async (req, res) => {
const data = fs.readFileSync("datas/archives.json", "UTF8");
const response = JSON.parse(data.toString());
res.render("archives", { ...response });
});
/**
* tags Page
*/
app.get("/tags", async (req, res) => {
const data = fs.readFileSync("datas/tags.json", "UTF8");
const response = JSON.parse(data.toString());
res.render("tags", { ...response });
});
/**
* tag Page
*/
app.get("/tag/:tagName", async (req, res) => {
const data = fs.readFileSync("datas/tag.json", "UTF8");
const response = JSON.parse(data.toString());
res.render("tag", { ...response });
});
//使用8080端口
app.listen(3001);
console.log("The server is running on 3001");