-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
37 lines (30 loc) · 826 Bytes
/
server.ts
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
const express = require('express');
const bodyParser = require('body-parser');
const md = require('markdown-it')();
const PORT = process.env.PORT || 3000;
const app = express();
app.use(bodyParser.json());
// 转化 markdown 接口
app.use('/api/transform-markdown', function (req, res) {
if (req.body) {
if (req.body.markdown) {
let html = md.render(req.body.markdown);
res.send({
msg: '获取成功',
data: html,
code: 200
});
} else {
res.send({
msg: '参数错误',
code: 400
});
}
} else {
res.send({
msg: '参数错误',
code: 400
});
}
});
app.listen(PORT,() => console.log('listening:' + PORT));