firebase / firebase/firebase-tools

HTTP functions req.params is prefixed with "/"

Open
#3,209 4 comments 0 reactions 0 assignees View on GitHub
emulator-suite help-wanted internal-bug-filed type: bug
Dominant language
TypeScript
Stars
4.5k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
84

Description

### [REQUIRED] Environment info

**firebase-tools:**
9.6.1

**Platform:**
macOS

### [REQUIRED] Test case

When you use Cloud Functions with Hosting rewrites, you can get the path from req.params[0]. This value is different between local emulator and production.

```typescript
import * as functions from "firebase-functions";

export const checkReqParams = functions.https.onRequest((req, res) => {
res.status(200).send(req.params);
});
```

https://github.com/dora1998/firebase-tools-req-params

### [REQUIRED] Steps to reproduce

1. Access to `http://localhost:5000/foobar` (using hosting rewrites)
2. You'll see the response below.

```json
{
"0": "/foobar"
}
```

3. However, the response changes when you run this function in production.

```json
{
"0": "foobar"
}
```

### [REQUIRED] Expected behavior

req.params[0] is not prefixed with `/` (same as production environment)

### [REQUIRED] Actual behavior

req.params[0] is prefixed with `/` only in local emulator, not in production.

Contributor guide

Open the contributing guide

Research direction

Start with the linked firebase-tools-req-params reproduction and the reported firebase-tools 9.6.1 local Hosting rewrite case, then compare req.params[0] from the emulator with production. Done means the local response for /foobar matches production and no longer includes the leading slash.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.