Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy #61

Open
gadieichhorn opened this issue Mar 31, 2016 · 6 comments
Open

proxy #61

gadieichhorn opened this issue Mar 31, 2016 · 6 comments

Comments

@gadieichhorn
Copy link

its more of a question than an issue...

I am following the NG2 ToH pattern and need to add a proxy to my local server API but would like to keep it simple from the command prompt in the node script section of the package.json

any url calls to /server/api
redirect to
http://192.168.99.100/server/api

thanks

@cgmartin
Copy link
Collaborator

cgmartin commented Apr 5, 2016

@gadieichhorn This should be possible by adding a proxy middleware in a custom bs-config.js, ie: http-proxy-middleware
https://github.com/chimurai/http-proxy-middleware/blob/master/examples/browser-sync/index.js

@Joebob12
Copy link

Joebob12 commented Apr 5, 2016

Has anyone been able to put in a bs-config file and get it working? I'm Actually getting in the terminal a "Did not detect a 'bs-config.json' or 'bs-config.js' overide file using lite-server defaults when I have it in my directory. See image of test project error here Not sure if i'm going crazy or not.

@cgmartin
Copy link
Collaborator

cgmartin commented Apr 5, 2016

@gadieichhorn here is a working example with lite-server

Run:

$ npm install --save-dev http-proxy-middleware connect-history-api-fallback

File: bs-config.js

var proxyMiddleware = require('http-proxy-middleware');
var fallbackMiddleware = require('connect-history-api-fallback');

module.exports = {
    server: {
        middleware: {
            1: proxyMiddleware('/api', {
                target: 'http://www.example.org',
                changeOrigin: true   // for vhosted sites, changes host header to match to target's host
            }),

            2: fallbackMiddleware({
                index: '/index.html', verbose: true
            })
        }
    }
};

@maximedupre
Copy link

I think the history middleware should be before the proxy middleware. For some reason, when the proxy middleware is first, it never reaches the history one.

@chimurai
Copy link

chimurai commented May 5, 2016

Thanks @cgmartin for the example.

Added lite-server to the list of examples:
https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/servers.md#lite-server

@pabl-o-ce
Copy link

pabl-o-ce commented Sep 16, 2016

thanks it works @cgmartin and @maximedupre! keep with the good work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants