0

I need an express redirect/rewrite to my backend( accepts https only on a specific port) and also to keep serving the static files(frontend) , but seems that I have something wrong ..

 var express = require('express');
var app = express();
var modRewrite = require('connect-modrewrite');


app.use("/",express.static(__dirname + "/build"));

app.use(modRewrite([
  '^/auth/signin https://127.0.0.1:8444/auth/signin'
]));

var server = app.listen(8000, function () {
  var host = server.address().address;
  var port = server.address().port;

  console.log('App listening at http://%s:%s', host, port);
});
Luis
  • 1,242
  • 11
  • 18
  • Do you really need express for this? nginx is better in ssl termination, reverse proxy to node and serving static assets. – Swaraj Giri Jul 23 '15 at 06:18
  • I'm open to use another thing instead of connect-modrewrite too – Luis Jul 23 '15 at 06:18
  • Heres the gist. 1. use nginx to terminate ssl and as a reverse proxy to the node process. 2. use nginx to serve static files. **Edit** - Add link for the above. http://stackoverflow.com/a/10375750/710005 – Swaraj Giri Jul 23 '15 at 06:19
  • Yeah I know ! , but this is for development so I run this file , in prod I have the nginx :) , but for development I don't want to install a local nginx too much config for new developers to config the project. – Luis Jul 23 '15 at 06:22
  • 1
    It's not that difficult, neither is it time consuming. I can write you a gist on how to setup. bonus points - set up vagrant/docker and share that with you team. Does not get any easier that this. – Swaraj Giri Jul 23 '15 at 06:25
  • thank you @SwarajGiri , if no one else have a solution I will end up doing that ! :) , I had some trouble install nginx in mac (brew didn't install it correctly) , so I guess I can try vagrant! , not docker because I need a development environment with easy GUI access ,someones will prefer IDE rather than vim , thank you for your fast response ! – Luis Jul 23 '15 at 06:32

1 Answers1

1

Please change

app.use(modRewrite(['^/auth/signin https://127.0.0.1:8444/auth/signin']));

to

app.use(modRewrite(['^/auth/signin https://127.0.0.1:8444/auth/signin [P]']));

From the document: https://www.npmjs.com/package/connect-modrewrite#proxy-p

Proxy [P]
Proxy your requests

'^/test/proxy/(.*)$ http://nodejs.org/$1 [P]'
BlackMamba
  • 10,054
  • 7
  • 44
  • 67
  • good catch ! @BlackMamba , after adding the P and adding process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0" , the https proxy works :) – Luis Jul 23 '15 at 17:34