Created
November 13, 2018 05:49
-
-
Save ryanblock/5ccb48883da230daf5787bb1255689a1 to your computer and use it in GitHub Desktop.
Architect + ES Modules - example Lambda
This file contains 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 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