Skip to content

Instantly share code, notes, and snippets.

@ryanblock
Created November 13, 2018 05:49
Show Gist options
  • Save ryanblock/5ccb48883da230daf5787bb1255689a1 to your computer and use it in GitHub Desktop.
Save ryanblock/5ccb48883da230daf5787bb1255689a1 to your computer and use it in GitHub Desktop.
Architect + ES Modules - example Lambda
const fs = require('fs')
const join = require('path').join
exports.handler = async function http(req) {
let module = req.params.module
let filePath = join(__dirname, 'node_modules', '@architect', 'views', module)
let exists = fs.existsSync(filePath)
if (exists) {
let file = fs.readFileSync(filePath).toString()
return {
type: 'text/javascript; charset=utf8',
body: file
}
} else {
return {
status: 404,
type: 'text/html; charset=utf8',
body: `${module} not found`
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment