Skip to content
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

Firebase functions emulator ignores region #3031

Closed
JaapWeijland opened this issue Jan 14, 2021 · 7 comments · Fixed by #3033
Closed

Firebase functions emulator ignores region #3031

JaapWeijland opened this issue Jan 14, 2021 · 7 comments · Fixed by #3033
Assignees

Comments

@JaapWeijland
Copy link

[REQUIRED] Environment info

firebase-tools:
9.2.0

Platform:
macOS

[REQUIRED] Test case

export const api = region('europe-west3').https.onRequest(server);

When starting the emulator, the emulator correctly outputs the following URL:

✔ functions[api]: http function initialized (http://localhost:5000/**[some-project]**/europe-west3/api).

However, when visiting that URL, a 404 is given. Going to the following URL works however:

http://localhost:5000/**[some-project]**/us-central1/api

[REQUIRED] Steps to reproduce

See above

[REQUIRED] Expected behavior

Hitting the europe-west3 URL working like the us-central1 version does.

[REQUIRED] Actual behavior

The europe-west3 version hits a 404, while us-central1 works.

@samtstern samtstern self-assigned this Jan 14, 2021
@samtstern samtstern added the Needs: Author Feedback Issues awaiting author feedback label Jan 14, 2021
@samtstern
Copy link
Contributor

@JaapWeijland I am not able to reproduce this behavior. Here are my two functions:

const functions = require("firebase-functions");

exports.helloWorld = functions.https.onRequest((req,res) => {
    res.send("Hello, America\n");
});

exports.helloEurope = functions.region('europe-west3').https.onRequest((req, res) => {
    res.send("Hello, Europe\n");
});

When I run firebase emulators:start I see these logs (among others):

✔  functions[helloWorld]: http function initialized (http://localhost:5001/fir-dumpster/us-central1/helloWorld).
✔  functions[helloEurope]: http function initialized (http://localhost:5001/fir-dumpster/europe-west3/helloEurope).

I am able to curl both functions:

$ curl http://localhost:5001/fir-dumpster/us-central1/helloWorld
Hello, America
$ curl http://localhost:5001/fir-dumpster/europe-west3/helloEurope
Hello, Europe

Is there more to your situation? Do you possibly have two functions with the same name in different regions? If so that's a known limitation of the emulator right now.

@JaapWeijland
Copy link
Author

JaapWeijland commented Jan 14, 2021

Thanks for your answer! I oversimplified my example a bit.

What I actually have, is the following:

import {NestFactory} from '@nestjs/core';
import {AppModule} from './app.module';
import * as helmet from 'helmet';

import {ExpressAdapter} from '@nestjs/platform-express';
import * as express from 'express';
import {region} from 'firebase-functions';

const server = express();

server.get('/', (req, res) => {
    res.send('lol!');
});

// export const createNestServer = async (expressInstance: express.Express) => {
//     const _app = await NestFactory.create(AppModule, new ExpressAdapter(expressInstance), {
//         cors: true,
//     });
//     // app.use(helmet()); // protect from HTTP vulnerabilities
//     await _app.init();
// };

// createNestServer(server)
//     .then((v) => console.log('Nest Ready'))
//     .catch((err) => console.error('Nest broken', err));

export const api = region('europe-west3').https.onRequest(server);

export const europe = region('europe-west3').https.onRequest((req, res) => {
    res.send('Hello Europe');
});

I deliberately left the comments there. As you see, I'm experimenting with NestJS on Firebase. If filtered the issue down to be associated with Express though, so I'm not sure if NestJS has to do with anything here.

As you see, I gave the Express server to the endpoint to handle the traffic. For testing purposes, I added a regular signature to another endpoint. the api endpoint does not work with the europe-west3 region, however, it works with us-central1. The europe endpoint does work as intended.

So, I think it has something to do with Express.

Edit:

My compiled JS looks like this:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.europe = exports.api = void 0;
const express = require("express");
const firebase_functions_1 = require("firebase-functions");
const server = express();
server.get('/', (req, res) => {
    res.send('lol!');
});
exports.api = firebase_functions_1.region('europe-west3').https.onRequest(server);
exports.europe = firebase_functions_1.region('europe-west3').https.onRequest((req, res) => {
    res.send('Hello Europe');
});

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Jan 14, 2021
@samtstern
Copy link
Contributor

@JaapWeijland ah that helps thanks! I was able to roll a fix into this PR I was already working on:
#3033

@samtstern
Copy link
Contributor

@JaapWeijland can you show me the smallest test case that reproduces the issue on the latest version?

@samtstern samtstern reopened this Jan 18, 2021
@JaapWeijland
Copy link
Author

Ha Sam, I already deleted my comment. I was still using the old version when I thought I installed the newer one. I can confirm that latest version fixes the issue.

@samtstern
Copy link
Contributor

@JaapWeijland oh thank you! I use GitHub through my email mostly so I didn't notice it was deleted. Appreciate the super fast reply.

@dzivoing
Copy link

This is still happening to me i have tried

setGlobalOptions({ region: 'europe-west1' });

and

export const myFunction = onRequest({
  region: "europe-west1"
}, async (req: any, res: any) => {
});

For some reason emulator always runs with us-central1

http://127.0.0.1:5001/myProject/us-central1/myFunction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy