Created
January 19, 2022 03:33
-
-
Save pscheit/505e194ddfeec157dd558bd07b9548ca to your computer and use it in GitHub Desktop.
A small express server to execute markdown to story blok richtext in a node container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node: | |
image: node:17 | |
command: ["node", "src/nodejs/express-server-converter-app.js"] | |
working_dir: /app | |
ports: | |
- 83:80 | |
volumes: | |
- .:/app | |
- /var/www/.cache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const app = express() | |
const port = 80 | |
const markdownToRichtext = require('storyblok-markdown-richtext').markdownToRichtext | |
app.use(express.text()) | |
app.get('/', (req, res) => { | |
res.send('hi there post to /convert with markdown as body and retrieve json back') | |
}) | |
app.post('/convert', (req, res) => { | |
const richtextData = markdownToRichtext(req.body) | |
res.setHeader('Content-Type', 'application/json'); | |
res.send(JSON.stringify(richtextData)); | |
}) | |
const server = app.listen(port, "0.0.0.0", () => { | |
console.log(`Converter app listening at http://0.0.0.0:${port}`) | |
}) | |
process.on('SIGTERM', () => { | |
console.log('SIGTERM signal received: closing HTTP server') | |
server.close(() => { | |
console.log('HTTP server closed') | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment