optic icon indicating copy to clipboard operation
optic copied to clipboard

Ignore "commands/start" ability for `api init`

Open khainx-developer opened this issue 7 years ago • 5 comments

Hi team, I am a .NET developer and I am using Windows to work. I have a suggestion for api init to give an option to ignore command/start.

name: MyAPIs
commands: // ignore this
  start: dotnet run --project ./WebApi/WebApi.csproj
proxy:
  target: 'http://localhost:51859' // assign development port ENV.OPTIC_API_PORT 
  port: '5005'

When I start my APIs by Visual Studio, IIS Express web server create "http://localhost:51859" so I don't need command/start. And can I have ability to give development port for ENV.OPTIC_API_PORT instead of changing development port manually?

khainx-developer avatar Sep 10 '19 03:09 khainx-developer

Hey!

The changes you made in proxy.target should work the way you expect, with the Optic Proxy running on 5005 and forwarding traffic to your server at 51859. As long as you route your development traffic from the web app to 5005 everything should work fine.

We definitely need a better integration path for .NET.

For commands.start, I can add the ability to skip it. For now try making it

echo "Skipping..." &&

That should keep the proxy running until your CTRL-C

Can you try that for now? I'll get a more robust fix out soon.

acunniffe avatar Sep 10 '19 03:09 acunniffe

@acunniffe Thanks a lot. I used echo "Skipping..." && pause for Windows command

khainx-developer avatar Sep 10 '19 03:09 khainx-developer

Hi this is also what I need for my project, but it seems that the structure of the config file changed. Where to put the proxy.target?

palmtop avatar May 06 '20 12:05 palmtop

I have figured it out from the TaskToStartConfig in workspaces/cli-config/src/index.ts.

name: backend
tasks:
  start:
    command: 'sleep infinity'
    baseUrl: http://localhost:80
    proxy: http://localhost:9080
ignoreRequests:
- OPTIONS *

If you provide only base URL then optic will listen on that address and send calls to the same address except the port, where it utilizes a random generated port. If you provide proxy then optic listens on the address given in proxy and sends calls to the url in the baseURL.

palmtop avatar May 06 '20 14:05 palmtop

That's correct -- We can make it so that Optic will keep alive if no command is provided, or if you have a different structure in mind for these kinds of tasks we're open to ideas.

I need to update the docs to include this example.

acunniffe avatar May 06 '20 14:05 acunniffe