schickling / gulp-webserver

Streaming gulp plugin to run a local webserver with LiveReload
https://www.npmjs.org/package/gulp-webserver
MIT License
355 stars 84 forks source link

Wildcard characters for proxy sources #93

Open ValeryIvanov opened 9 years ago

ValeryIvanov commented 9 years ago

Is it possible to add support for wildcard chars for proxy sources.

Say I have requests i want to capture ends with '.do' then source will be like '/*.do'.

Thanks for your help!

chimurai commented 9 years ago

This can be achieved easily with http-proxy-middleware:

Example:

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

gulp.task('webserver', function() {
  gulp.src('app')
    .pipe(webserver({
      livereload: true,
      directoryListing: true,
      open: true,
      middleware: [
        proxy('/api**', {target: 'http://www.example.org', changeOrigin: true})
      ]
    }));
});

gulp.task('default', ['webserver']);

More on the wildcard options can be found on: https://github.com/chimurai/http-proxy-middleware#context-matching