-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.js
61 lines (52 loc) · 1.55 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
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 dataPath = path.join(__dirname, '/mock/list.json').replace(/\\/g, "\/");
let listData = JSON.parse(fs.readFileSync(dataPath));
res.render('index', listData)
})
/**
* Post Page
*/
app.get('/post/:postName', async (req, res) => {
const dataPath = path.join(__dirname, '/mock/post.json').replace(/\\/g, "\/");
let listData = JSON.parse(fs.readFileSync(dataPath));
res.render('post', listData)
})
/**
* Archives Page
*/
app.get('/archives', async (req, res) => {
const dataPath = path.join(__dirname, '/mock/archives.json').replace(/\\/g, "\/");
let listData = JSON.parse(fs.readFileSync(dataPath));
res.render('archives', listData)
})
/**
* tags Page
*/
app.get('/tags', async (req, res) => {
const dataPath = path.join(__dirname, '/mock/tags.json').replace(/\\/g, "\/");
let listData = JSON.parse(fs.readFileSync(dataPath));
res.render('tags', listData)
})
/**
* tag Page
*/
app.get('/tag/:tagName', async (req, res) => {
const dataPath = path.join(__dirname, '/mock/tag.json').replace(/\\/g, "\/");
let listData = JSON.parse(fs.readFileSync(dataPath));
res.render('tag', listData)
})
//使用8080端口
app.listen(3001)
console.log("The server is running on 3001")