Last active
August 24, 2018 21:50
-
-
Save brianleroux/a37a0d0aef8a205c85540ead814370c1 to your computer and use it in GitHub Desktop.
a function that returns text/javascript esmodules; a function that renders an html page..
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
let begin = require('@architect/functions') | |
function index(req, res) { | |
let html = `<script type=module src=/js/entry.mjs></script>` | |
res({html}) | |
} | |
exports.handler = begin.html.get(route) |
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
import hi from '/js/hi.mjs' | |
console.log(hi()) |
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
export default function hi() { | |
return 'hi jchris 💓' | |
} |
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
let arc = require('@architect/functions') | |
let read = require('fs').readFileSync | |
let exists = require('path-exists').sync | |
let join = require('path').join | |
let ledger = {} | |
/** | |
* lambda function that dynamically loads clientside modules | |
*/ | |
function route (req, res) { | |
let requested = join(__dirname, req.params.page) | |
if (ledger[requested]) { | |
let js = ledger[requested] | |
res({js}) | |
} else if (exists(requested)) { | |
let js = read(requested).toString() | |
ledger[requested] = js | |
res({js}) | |
} else { | |
res({ | |
status: 404, | |
js: `console.log('failed to find ${requested}')` | |
}) | |
} | |
} | |
exports.handler = arc.js.get(route) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment