Skip to content

Instantly share code, notes, and snippets.

@scottcorgan
Created October 19, 2017 19:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottcorgan/e6e2a6941567ba425018d20a989ebbc3 to your computer and use it in GitHub Desktop.
Save scottcorgan/e6e2a6941567ba425018d20a989ebbc3 to your computer and use it in GitHub Desktop.
const fs = require('fs')
const path = require('path')
const { promisify } = require('util')
const express = require('express')
const elmStaticHtml = require('elm-static-html-lib').default
const readFile = promisify(fs.readFile)
const app = express();
const pathToClient = path.resolve(__dirname, '../client/src')
app.use(async (req, res) => {
const model = { url: req.url }
const options = { model, decoder: 'Main.decode' }
const [ indexHtml, appHtml ] = await Promise.all([
readFile(path.resolve(__dirname, '../client/static/index.html')),
elmStaticHtml(pathToClient, "Main.view", options)
])
res.send(indexHtml.toString().replace('{{app}}', appHtml))
})
app.listen(4000, () => console.log('http://localhost:4000'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment