Skip to content

Instantly share code, notes, and snippets.

@pscheit
Created January 19, 2022 03:33
Show Gist options
  • Select an option

  • Save pscheit/505e194ddfeec157dd558bd07b9548ca to your computer and use it in GitHub Desktop.

Select an option

Save pscheit/505e194ddfeec157dd558bd07b9548ca to your computer and use it in GitHub Desktop.

Revisions

  1. pscheit created this gist Jan 19, 2022.
    9 changes: 9 additions & 0 deletions docker-compose.dev.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    node:
    image: node:17
    command: ["node", "src/nodejs/express-server-converter-app.js"]
    working_dir: /app
    ports:
    - 83:80
    volumes:
    - .:/app
    - /var/www/.cache
    28 changes: 28 additions & 0 deletions express-server-converter-app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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')
    })
    })