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.77k stars 187 forks source link

cloud.Api - static port for api simulator #2271

Open RaphaelManke opened 1 year ago

RaphaelManke commented 1 year ago

Feature Spec

I would like to have a static port when the cloud.Api resource is started in simulator.

Use Cases

This helps in cases where I develop against the api e.g. with a Frontend or want to make api calls with an external api client like insomnia oder postman. On top of that it enables the use of http reverse proxy like ngrok.

I discovered this lack of capability while developing a slack bot. To test it I used ngrok to forward the slack commands to the local machine.

Implementation Notes

No response

Component

SDK, Wing Console

Community Notes

Chriscbr commented 1 year ago

I think we will need a solution for this and for the cloud.Website resource - cc @tsuf239

brainstorming some ideas...

bring cloud;
bring sim;

let api = new cloud.Api();
(<sim.Api>api).set_port(3000); // casting mechanism -- will fail if you compile to `tf-aws`
RaphaelManke commented 1 year ago

I would add an idea like http://localhost:<staticPort>/<apiIdentifier>

This allows a port be defined by the user e.g. if a default port is not suitable and also support multiple APIs in an wing app.

The apiIdentifier could be something like the node hash.

eladb commented 1 year ago

This is a duplicate with #2227 -- I am not sure a static port is necessarily the correct way to address this use case.

skorfmann commented 1 year ago

This is a duplicate with #2227 -- I am not sure a static port is necessarily the correct way to address this use case.

@eladb I'm not sure that #2227 is really covering this. I think exposing a service to the public internet is quite a different use-case from wanting to have a locally available, static port - even if not necessarily technically, certainly from an organizational policy point of view e.g.: I might have another application I develop running locally (no matter if frontend or backend), where all I want is a known address to a Wing API. In particular in enterprise contexts, I could see this become a dealbreaker if the only option was exposing this via something like ngrok.

Chriscbr commented 1 year ago

I agree I think some more discussion is needed, also this issue does not only pertain to webhooks (webhooks just happen to be one use case). Reopening

tsuf239 commented 1 year ago

We need one for the website as well :) my initial thought was to just let the user decide, inside the Api/website constructor made sense for me back then, but I do like @Chriscbr's in-code suggestion, (which we can even change a bit to avoid the user comment and uncomment the line of code to make the file compiles to both sim and aws)

let api = new cloud.Api();
if (utils.target == TARGETS.SIM ) { 
    api.setPort(3000); 
}
staycoolcall911 commented 10 months ago

Duplicates #2227

staycoolcall911 commented 10 months ago

Oops, missed some important comments on this issue... Reopening - we'll discuss it on a next team time

Chriscbr commented 4 months ago

We've made two changes that should help here:

Let us know if these improvements solve your use case(s). I'll downgrade this issue to P2 for now - but if there are use cases or situations that aren't addressed by these changes, I think it could still be feasible to support static ports via an optional custom platform parameter: https://www.winglang.io/docs/concepts/platforms#defining-custom-platform-parameters

github-actions[bot] commented 1 month 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!