Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,15 @@ jobs:
fi
echo "✓ functions.yaml exists"

- name: Create .env.local for params
run: |
cat > example/basic/.env.local << 'EOF'
WELCOME_MESSAGE=Hello from Dart Functions!
MIN_INSTANCES=0
IS_PRODUCTION=false
EOF
echo "✓ Created .env.local with default param values"

- name: Run E2E tests
run: dart test test/e2e/e2e_test.dart --reporter=expanded
timeout-minutes: 5
Expand Down
60 changes: 58 additions & 2 deletions example/basic/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,67 @@
import 'package:firebase_functions/firebase_functions.dart';

// =============================================================================
// Parameterized Configuration Examples
// =============================================================================

// Define parameters - these are read from environment variables at runtime
// and can be configured at deploy time via .env files or CLI prompts.
final welcomeMessage = defineString(
'WELCOME_MESSAGE',
ParamOptions(
defaultValue: 'Hello from Dart Functions!',
label: 'Welcome Message',
description: 'The greeting message returned by the helloWorld function',
),
);

final minInstances = defineInt(
'MIN_INSTANCES',
ParamOptions(
defaultValue: 0,
label: 'Minimum Instances',
description: 'Minimum number of instances to keep warm',
),
);

final isProduction = defineBoolean(
'IS_PRODUCTION',
ParamOptions(
defaultValue: false,
description: 'Whether this is a production deployment',
),
);

void main(List<String> args) {
fireUp(args, (firebase) {
// HTTPS onRequest example
// HTTPS onRequest example - using parameterized configuration
firebase.https.onRequest(
name: 'helloWorld',
(request) async => Response.ok('Hello from Dart Functions!'),
// ignore: non_const_argument_for_const_parameter
options: HttpsOptions(
// Use parameters in options - evaluated at deploy time
minInstances: DeployOption.param(minInstances),
),
(request) async {
// Access parameter value at runtime
return Response.ok(welcomeMessage.value());
},
);

// Conditional configuration based on boolean parameter
firebase.https.onRequest(
name: 'configuredEndpoint',
// ignore: non_const_argument_for_const_parameter
options: HttpsOptions(
// Use thenElse for conditional configuration at deploy time
// isProduction.thenElse(trueValue, falseValue) returns an expression
memory: Memory.expression(isProduction.thenElse(2048, 512)),
),
(request) async {
// Access parameter value at runtime
final env = isProduction.value() ? 'production' : 'development';
return Response.ok('Running in $env mode');
},
);

// Pub/Sub trigger example
Expand Down
51 changes: 48 additions & 3 deletions example/nodejs_reference/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,57 @@

const { onRequest } = require("firebase-functions/v2/https");
const { onMessagePublished } = require("firebase-functions/v2/pubsub");
const { defineString, defineInt, defineBoolean } = require("firebase-functions/params");

// HTTPS onRequest example
exports.helloWorld = onRequest((request, response) => {
response.send("Hello from Dart Functions!");
// =============================================================================
// Parameterized Configuration Examples
// =============================================================================

// Define parameters - these are read from environment variables at runtime
// and can be configured at deploy time via .env files or CLI prompts.
const welcomeMessage = defineString("WELCOME_MESSAGE", {
default: "Hello from Dart Functions!",
label: "Welcome Message",
description: "The greeting message returned by the helloWorld function",
});

const minInstances = defineInt("MIN_INSTANCES", {
default: 0,
label: "Minimum Instances",
description: "Minimum number of instances to keep warm",
});

const isProduction = defineBoolean("IS_PRODUCTION", {
default: false,
description: "Whether this is a production deployment",
});

// HTTPS onRequest example - using parameterized configuration
exports.helloWorld = onRequest(
{
// Use parameters in options - evaluated at deploy time
minInstances: minInstances,
},
(request, response) => {
// Access parameter value at runtime
response.send(welcomeMessage.value());
}
);

// Conditional configuration based on boolean parameter
exports.configuredEndpoint = onRequest(
{
// Use thenElse for conditional configuration at deploy time
// isProduction.thenElse(trueValue, falseValue) returns an expression
memory: isProduction.thenElse(2048, 512),
},
(request, response) => {
// Access parameter value at runtime
const env = isProduction.value() ? "production" : "development";
response.send(`Running in ${env} mode`);
}
);

// Pub/Sub trigger example
exports.onMessagePublished_mytopic = onMessagePublished(
"my-topic",
Expand Down
Loading
Loading