winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.85k stars 189 forks source link

cloud.Api catch-all route handler #3983

Open Chriscbr opened 11 months ago

Chriscbr commented 11 months ago

Feature Spec

A preflight API for running inflight code that should run on all uncaught routes of a cloud.Api:

bring cloud;

let api = new cloud.Api();

api.get("/users/*", inflight (req) => { /* ... */ });
api.get("*", inflight (req) => { /* ... */ });

Since req: cloud.ApiRequest includes path as a field, the inflight function can perform custom logic based on the actual route the user passed.

Related to https://github.com/winglang/wing/pull/3973, https://github.com/winglang/wing/issues/1848

Use Cases

Specifying custom responses for when a request doesn't match any of the other routes you've specified on your cloud.Api.

This kind of capability is available in other frameworks like Express.js using the "*" syntax (see examples here) and SST using the "{proxy+}" path variable (docs).

Implementation Notes

No response

Component

SDK

Community Notes

github-actions[bot] commented 8 months ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

skorfmann commented 5 months ago

This would be pretty handy for cases where people would wanna use 3rd party frameworks. here's an example https://github.com/winglang/examples/pull/45

github-actions[bot] commented 2 months ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!