Skip to content

Instantly share code, notes, and snippets.

@joshlarsen

joshlarsen/app.js

Created Mar 19, 2019
Embed
What would you like to do?
Google Cloud Functions Node.js 8 Simple Emulator
/**
* 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
You can’t perform that action at this time.