Skip to content

Commit 725ae2a

Browse files
committed
[NI] handle trailing slash and expose full error
1 parent 5a34ac4 commit 725ae2a

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

examples/browser-api-playground/server.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,38 @@ app.use(cors());
1111
app.post("/generateAuthToken", (req, res) => {
1212
// Extract the backend and user from the request
1313
const { backend, actAs, apiKey } = req.body;
14+
const tokenApiPath = backend.endsWith("/")
15+
? `${backend}rest/api/v1/createauthtoken`
16+
: `${backend}/rest/api/v1/createauthtoken`;
1417

1518
// Call the Glean server's createauthtoken endpoint
1619
axios({
1720
method: "POST",
18-
url: `${backend}/rest/api/v1/createauthtoken`,
21+
url: tokenApiPath,
1922
headers: {
2023
Authorization: `Bearer ${apiKey}`,
2124
"X-Scio-Actas": actAs,
2225
accept: "application/json",
2326
},
2427
})
2528
.then((response) => res.json(response.data))
26-
.catch((error) => res.status(500).json({ error: error.message }));
29+
.catch((error) => res.status(500).json({ error: error }));
2730
});
2831

2932
app.post("/generateAnonymousAuthToken", (req, res) => {
3033
// Extract the backend and user from the request
3134
const { backend, actAs } = req.body;
35+
const tokenApiPath = backend.endsWith("/")
36+
? `${backend}rest/api/v1/createanonymoustoken`
37+
: `${backend}/rest/api/v1/createanonymoustoken`;
3238

3339
// Call the Glean server's createanonymoustoken endpoint
3440
axios({
3541
method: "post",
36-
url: `${backend}/api/v1/createanonymoustoken`,
42+
url: tokenApiPath,
3743
})
3844
.then((response) => res.json(response.data))
39-
.catch((error) => res.status(500).json({ error: error.message }));
45+
.catch((error) => res.status(500).json({ error: error }));
4046
});
4147

4248
app.listen(port, () => {

0 commit comments

Comments
 (0)