Skip to content

Instantly share code, notes, and snippets.

@pscheit
Created January 19, 2022 03:33
Show Gist options
  • Save pscheit/505e194ddfeec157dd558bd07b9548ca to your computer and use it in GitHub Desktop.
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
node:
image: node:17
command: ["node", "src/nodejs/express-server-converter-app.js"]
working_dir: /app
ports:
- 83:80
volumes:
- .:/app
- /var/www/.cache
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