-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Update functions template to meet modern dev practices. #9287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
taeold
wants to merge
4
commits into
master
Choose a base branch
from
functions-init-modernization
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/latest/schema.json", | ||
"formatter": { | ||
"enabled": true, | ||
"indentStyle": "space" | ||
}, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,28 @@ | ||
/** | ||
* Import function triggers from their respective submodules: | ||
* | ||
* const {onCall} = require("firebase-functions/v2/https"); | ||
* const {onDocumentWritten} = require("firebase-functions/v2/firestore"); | ||
* | ||
* See a full list of supported triggers at https://firebase.google.com/docs/functions | ||
*/ | ||
import { setGlobalOptions } from "firebase-functions"; | ||
import * as logger from "firebase-functions/logger"; | ||
import { onRequest } from "firebase-functions/https"; | ||
|
||
const {setGlobalOptions} = require("firebase-functions"); | ||
const {onRequest} = require("firebase-functions/https"); | ||
const logger = require("firebase-functions/logger"); | ||
// Start writing functions: | ||
// https://firebase.google.com/docs/functions | ||
|
||
// For cost control, you can set the maximum number of containers that can be | ||
// running at the same time. This helps mitigate the impact of unexpected | ||
// traffic spikes by instead downgrading performance. This limit is a | ||
// per-function limit. You can override the limit for each function using the | ||
// `maxInstances` option in the function's options, e.g. | ||
// `onRequest({ maxInstances: 5 }, (req, res) => { ... })`. | ||
// NOTE: setGlobalOptions does not apply to functions using the v1 API. V1 | ||
// functions should each use functions.runWith({ maxInstances: 10 }) instead. | ||
// In the v1 API, each function can only serve one request per container, so | ||
// this will be the maximum concurrent request count. | ||
setGlobalOptions({ maxInstances: 10 }); | ||
setGlobalOptions({ | ||
// For cost control, you can set the maximum number of containers that can be | ||
// running at the same time. This helps mitigate the impact of unexpected | ||
// traffic spikes by instead downgrading performance. This limit is a | ||
// per-function limit. You can override the limit for each function using the | ||
// `maxInstances` option in the function's options, e.g. | ||
// `onRequest({ maxInstances: 5 }, (req, res) => { ... })`. | ||
maxInstances: 10, | ||
// Tip: event-driven triggers must run in the same region as the Firebase | ||
// services they listen to (Firestore, Storage, etc.). | ||
region: "us-central1", | ||
}); | ||
|
||
// Create and deploy your first functions | ||
// https://firebase.google.com/docs/functions/get-started | ||
|
||
// exports.helloWorld = onRequest((request, response) => { | ||
// logger.info("Hello logs!", {structuredData: true}); | ||
// response.send("Hello from Firebase!"); | ||
// }); | ||
export const helloWorld = onRequest((_request, response) => { | ||
logger.info("Hello from Firebase!", { structuredData: true }); | ||
response.send("Hello from Firebase!"); | ||
}); |
21 changes: 12 additions & 9 deletions
21
.../functions/javascript/package.nolint.json → ...es/init/functions/javascript/package.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
{ | ||
"name": "functions", | ||
"description": "Cloud Functions for Firebase", | ||
"type": "module", | ||
"private": true, | ||
"engines": { | ||
"node": "{{RUNTIME}}" | ||
}, | ||
"main": "index.js", | ||
"scripts": { | ||
"lint": "biome lint .", | ||
"format": "biome format --write .", | ||
"serve": "firebase emulators:start --only functions", | ||
"shell": "firebase functions:shell", | ||
"start": "npm run shell", | ||
"deploy": "firebase deploy --only functions", | ||
"logs": "firebase functions:log" | ||
}, | ||
"engines": { | ||
"node": "{{RUNTIME}}" | ||
}, | ||
"main": "index.js", | ||
"dependencies": { | ||
"firebase-admin": "^12.6.0", | ||
"firebase-functions": "^6.0.1" | ||
"firebase-admin": "^13.5.0", | ||
"firebase-functions": "^6.4.0" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "^2.2.5", | ||
"firebase-functions-test": "^3.1.0" | ||
}, | ||
"private": true | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.