-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebserver.js
80 lines (69 loc) · 1.79 KB
/
webserver.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const express = require('express')
const fs = require('fs')
const path = require('path')
const marked = require('marked')
const app = express()
const port = process.env.PORT || 8080
app.use(express.static('public'))
app.get('/', (req, res) => {
const readmePath = path.join(__dirname, 'README.md')
fs.readFile(readmePath, 'utf8', (err, data) => {
if (err) {
res.status(500).send('Error reading README file.')
} else {
marked.setOptions({
mangle: false,
headerIds: false,
})
const markdownContent = marked.parse(data.toString())
const html = `
<!DOCTYPE html>
<html>
<head>
<title>CannyBot</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<style>
body {
font-family: 'Arial', sans-serif;
margin: 20px;
}
.container {
max-width: 800px;
margin: 0 auto;
}
h1 {
font-size: 32px;
margin-bottom: 10px;
}
h2 {
font-size: 26px;
margin-bottom: 10px;
}
h3 {
font-size: 22px;
margin-bottom: 10px;
}
p {
font-size: 16px;
line-height: 1.5;
}
code {
font-size: 16px;
}
</style>
</head>
<body>
<div class="container">
${markdownContent}
</div>
</body>
</html>
`
res.send(html)
}
})
})
app.listen(port, () => {
console.log(`The web server is running on port ${port}!`)
})
module.exports = app