Created
October 19, 2017 19:52
-
-
Save scottcorgan/e6e2a6941567ba425018d20a989ebbc3 to your computer and use it in GitHub Desktop.
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 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