-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathweb.js
42 lines (37 loc) · 922 Bytes
/
web.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
const fastify = require('fastify')();
const md = require('markdown-it')({
html: true,
});
fastify.register(require('@fastify/static'), {
root: require('path').join(__dirname, 'static')
});
fastify.addHook('preHandler', async (req, res) => {
res.header('Content-Security-Policy', [
"default-src 'self'",
"base-uri 'self'",
"frame-ancestors 'none'",
"img-src 'none'",
"object-src 'none'",
"script-src 'self' 'unsafe-eval'",
"script-src-attr 'none'",
"style-src 'self' 'unsafe-inline'"
].join(';'));
res.header('X-Content-Type-Options', 'nosniff');
});
fastify.get('/render', {
schema: {
query: {
type: 'object',
properties: {
content: {
type: 'string',
maxLength: 1000
}
},
required: ['content']
}
}
}, (req, res) => {
res.type('text/html').send(md.render(req.query.content));
});
fastify.listen(process.env.PORT || 3000, '::', () => console.log('listening'));