Skip to content

Instantly share code, notes, and snippets.

@novasush
Last active July 26, 2023 15:57
Show Gist options
  • Save novasush/302a6622bfa0e422960ce859e793f4f5 to your computer and use it in GitHub Desktop.
Save novasush/302a6622bfa0e422960ce859e793f4f5 to your computer and use it in GitHub Desktop.
Index.js for firebase function
const functions = require("firebase-functions");
const cors = require("cors");
const express = require("express");
const bodyParser = require('body-parser');
const compression = require("compression");
// Express app config
const tasksApp = express();
tasksApp.use(compression());
tasksApp.use(bodyParser.json());
tasksApp.use(bodyParser.urlencoded({ extended: false }));
tasksApp.use(cors({ origin: true }));
// A simple api to get all tasks
tasksApp.get("/", (request, response) => {
response.status(200).send([{
id: '123',
name: 'Task 1',
isComplete: false
},
{
id: '456',
name: 'Task 2',
isComplete: true
}]);
});
// tasks will be the name of the function as well as API
//in which we will pass our express app
exports.tasks = functions.https.onRequest(tasksApp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment