Created
March 19, 2019 18:38
-
-
Save joshlarsen/e74bec10a99641c0192ae37ae9e5d8f5 to your computer and use it in GitHub Desktop.
Google Cloud Functions Node.js 8 Simple Emulator
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
/** | |
* Inspiration taken from here https://github.com/GoogleCloudPlatform/cloud-functions-emulator/issues/258#issuecomment-413786762 | |
* Alternative: https://github.com/GoogleCloudPlatform/cloud-functions-emulator/issues/258#issuecomment-407996126 | |
* | |
* Original: https://github.com/GoogleCloudPlatform/cloud-functions-emulator/issues/258#issuecomment-437080813 | |
*/ | |
const express = require('express'); | |
const cors = require('cors'); | |
const bodyParser = require('body-parser'); | |
const app = express(); | |
app.use(cors()); | |
app.options('*', cors()); | |
const triggers = require('./index'); | |
app.use(bodyParser.json()); | |
const PORT = process.env.PORT || 8080; | |
for (let name in triggers) { | |
// create a trigger for every export | |
console.info(`Registered function http://localhost:${PORT}/${name}`); | |
app.post(`/${name}`, (request, response) => { | |
response.setTimeout(540000); | |
console.log(`hit -> ${name}`); | |
triggers[name](request, response); | |
}); | |
} | |
// Start the server | |
app.listen(PORT, () => { | |
console.log(`App listening on port ${PORT}`); | |
console.log('Press Ctrl+C to quit.'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment