Cogman
Cogman

Reputation: 2150

How do I handle post requests from my dart app ran from the dart editor?

I have code that looks something like this (_http is the angular Http object)

    var httpFuture = _http.post('/api/items', {
      'ids': JSON.encode(new List.from(nonLoadedIds))
    });
    httpFuture.catchError((e) {
      Logger.root.severe('Unable to load items!', e);
    });

It is making a post request to load a bunch of things. Potentially more ids than the http get header can handle.

The nice development experience would be if I could fire up the dart editor, mock up some fake response data, run my app, and see the data in the end. I would also accept being able to start up a separate web app and somehow proxy my post requests to that web app.

What I don't want to do is change my '/api/items' into something like 'http://localhost:8084/api/items' mostly because I don't want to have to remember to replace these before deploying (I know I'll forget) and while doable, I don't want to on my server implement CORS just to have to remember to disable it when I deploy to production.

But really, I would accept just about any workflow if it is recommended. I just would like to eliminate any manual code transformations pre production deploy.

Upvotes: 2

Views: 124

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657821

The suggested attempt is to use a simple proxy server which forwards to pub serve.

See for example https://code.google.com/p/dart/issues/detail?id=18039 This issue contains the source code for a simple custom proxy server example https://code.google.com/p/dart/issues/detail?id=15731

see also

Upvotes: 1

Related Questions