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

405 not Allowed error on POST call with gulp proxy #81

Closed
yobre opened this issue May 19, 2016 · 2 comments
Closed

405 not Allowed error on POST call with gulp proxy #81

yobre opened this issue May 19, 2016 · 2 comments
Labels

Comments

@yobre
Copy link

yobre commented May 19, 2016

Expected behavior

POST call currectly redirect to proxy port 9000

Actual behavior

redirect errror : 405 (Method Not Allowed)

Setup

  • http-proxy-middleware: 0.15.0
  • server: connect/express/browser-sync... + "express": "^4.13.4"
  • other relevant modules

Gulp task

gulp.task('connect', ['styles'], function() {

  var serveStatic = require('serve-static');
  var serveIndex = require('serve-index');
  var app = require('connect')()
    .use(require('connect-livereload')({port: 35729}))
    .use(serveStatic('.tmp'))
    .use(serveStatic('app'))
    // paths to bower_components should be relative to the current file
    // e.g. in app/index.html you should use ../bower_components
    .use('/bower_components', serveStatic('bower_components'))
    .use(serveIndex('app'))
    .use(require('express')());

  //////////////// PROXY START ////////////////

  // https://github.com/chimurai/http-proxy-middleware#context-matching
  var proxy = require('http-proxy-middleware');
  var options = {
    target: 'http://localhost:9000',
    changeOrigin: true
  };
  app.use('/api', proxy(options));

  //////////////// PROXY END ////////////////

  require('http').createServer(app)
    .listen(8000)
    .on('listening', function() {
      console.log('Started connect web server on http://localhost:8000');
    });
});

Stackoverflow answer: http://stackoverflow.com/questions/37302712/405-not-allowed-error-on-post-call-with-gulp-proxy

@chimurai
Copy link
Owner

I've made a minimal example for connect:
https://github.com/chimurai/http-proxy-middleware/blob/master/examples/connect/index.js

Try moving the proxy up, instead of configuring as the last middleware.

Not really sure what this is doing: .use(require('express')());

@yobre
Copy link
Author

yobre commented May 19, 2016

Thank you for your clean example @chimurai, i removed require('express')() (not really sure about it too) but nothing changed, then i also removed serveIndex('app') and everithing seem to work fine now.
maybe there was some conflict with serveStatic('app').

@yobre yobre closed this as completed May 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants