0

Lite server and Browser-sync are really nice tools for fast UI programming. My problem arise when I try ajax calls for data from my real web server.

It seems basic to me to get json objects via ajax call from a real server (java, php, c#, etc), and yet I can't seems to find any example how to do it.

please advise.

Avi
  • 1,924
  • 3
  • 17
  • 31

2 Answers2

1

I found the answer here: https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/servers.md#lite-server

File: bs-config.js

var proxy = require('http-proxy-middleware');

module.exports = {
    server: {
        middleware: {
            1: proxy('/forecasts', {
                target: 'http://api.aerisapi.com/forecasts/',
                changeOrigin: true   // for vhosted sites, changes host header to match to target's host
            }),
            2: require('connect-history-api-fallback')({index: '/index.html', verbose: true})
        }
    }
};
Avi
  • 1,924
  • 3
  • 17
  • 31
0

Use the Angular 2 Http service. Google for it and you'll find plenty of examples. This is a good start: https://angular.io/docs/ts/latest/guide/server-communication.html It does everything you'll need, including sending headers. Make sure your server is CORS enabled.

hholtij
  • 2,906
  • 6
  • 27
  • 42
  • Thanks, but I don't see here a simple solution to my problem. I can use CORS with absolute path, but this is no option for developing purpose only. I see another solution by implementing custom XHRBackend service, again, to complex and not reasonable. do you see another solution? – Avi Jun 26 '16 at 09:59