question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to have both static server and proxy in grunt

See original GitHub issue

Hello,

I’m trying to setup a configuration in grunt that use a static server for frontend code and a proxy for backend REST API, I can make it work one or the other but not both at same time, it just fails silently.

Ideally I’d like to be able to setup routes or regex to dispatch between the static server and the proxy: by default go to static server and for /api and few other URIs go through proxy.

browserSync: {
    dev: {
        bsFiles: {
            src : [
                'src/main/webapp/**/*.html',
                'src/main/webapp/**/*.json',
                'src/main/webapp/bower_components/**/*.{js,css}',
                '{.tmp/,}src/main/webapp/assets/styles/**/*.css',
                '{.tmp/,}src/main/webapp/scripts/**/*.js',
                'src/main/webapp/assets/images/**/*.{png,jpg,jpeg,gif,webp,svg}'
            ]
        }
    },
    options: {
        watchTask: true,
            server: {
            baseDir: [".tmp", "src/main/webapp"]
        },
        //            proxy: "localhost:8080"
    }
},

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mohanraocommented, Feb 9, 2017

Hi,

I am using browser-sync with proxy-middleware.

My Proxy redirect some requests. I want to avoid the redirect of the url and also from http to https. How to achived that?

1reaction
clirencommented, May 15, 2015

Here is my browserSync config task. The app checks to see if authentication is available, if not redirects to /auth page where user performs login. If the auth page is smart it redirects the user back to the original location, this time the auth cookie is present so starts calling /api. I haven’t done anything manually to add cookies, its behaving like it should in a production environment. I noticed one thing though, it doesn’t work over https but when I am running this locally, its all http.

var proxyMiddleware = require('http-proxy-middleware');
var proxyURL = 'http://localhost:8080';

gulp.task('browserSync', ['webpack', 'markup'], function() {
  var authProxy = proxyMiddleware('/auth', {target: proxyURL});
  var apiProxy = proxyMiddleware('/api', {target: proxyURL});

  config.server.middleware = [authProxy, apiProxy];

  browserSync(config);
});

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proxy Your Requests to the Backend Server With Grunt
The procedure to setup the Grunt proxy for backend requests is simple. First, you will have to add the proxy configuration to your...
Read more >
Setup authenticated corporate proxy in Grunt server
I am starting to work on an existing Angular JS application, however I am unable to get it working behind the corporate proxy....
Read more >
Using Grunt As Your Front End Dev Server | Greg Babiars's Blog
Grunt's wide range of makes it easy to create a dev server to both serve up our static files as well as proxy...
Read more >
Browsersync + Grunt.js
First, you'll need to install the Browsersync Plugin. ... be watching CSS files and using the built-in server for static HTML/CSS/JS files. ......
Read more >
Proxy Your Requests to the Backend Server With Grunt
The procedure to set up the proxy is simple. First, you will have to add the proxy configuration to your Gruntfile.js . In...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found