-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (50 loc) · 1.06 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
const express = require('express')
const request = require('request-promise')
const app = express()
const STATUS_CODE = {
INVALID_PARAMETER: 103,
INTERNAL_ERROR: 102
}
app.get('/', (req, res) => {
const url = req.query.url
if (!url) {
res.send({
type: 'Error',
data: [{
code: STATUS_CODE.INVALID_PARAMETER,
message: '缺少 URL'
}]
})
}
const API_URL = `http://heckyesmarkdown.com/go/?u=${url}`
request(API_URL)
.then(html => {
if (!html) {
res.send({
type: 'Error',
data: [{
code: STATUS_CODE.INVALID_PARAMETER,
message: '未返回数据'
}]
})
}
res.send({
type: 'Text',
data: [html]
})
})
.catch(err => {
console.error(err)
console.error(err.stack)
res.send({
type: 'Error',
data: [{
code: STATUS_CODE.INTERNAL_ERROR,
message: err.toString()
}]
})
})
})
app.listen(3000, () => {
console.log('app listening on port 3000')
})