forked from demisto/content-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdx-parse-server.js
35 lines (31 loc) · 895 Bytes
/
mdx-parse-server.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
const mdx = require('@mdx-js/mdx');
const http = require('http')
function requestHandler(req, res) {
// console.log(req)
if (req.method != 'POST') {
res.statusCode = 405
res.end('Only POST is supported')
}
let body = ''
req.setEncoding('utf8');
req.on('data', function (data) {
body += data
})
req.on('end', async function () {
// console.log('Body length: ' + body.length)
try {
parsed = await mdx(body)
res.end('Successfully parsed mdx')
} catch (error) {
res.statusCode = 500
res.end("MDX parse failure: " + error)
}
})
}
const server = http.createServer(requestHandler);
server.listen(6060, (err) => {
if (err) {
return console.log('something bad happened', err)
}
console.log(`MDS server is listening on port: 6060`)
});