BRo*_*ers 19 node.js express node-http-proxy
我正在尝试做这样的事情:
// Setup prox to handle blog requests
httpProxy.createServer({
hostnameOnly: true,
router: {
'http://localhost': '8080',
'http://localhost/blog': '2368'
}
}).listen(8000);
Run Code Online (Sandbox Code Playgroud)
以前我用过这个:
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
Run Code Online (Sandbox Code Playgroud)
基本上,我想仍然使用快递...但是,当人们去http://localhost/blog博客但仍然被服务port 8080(最终将是80端口)
所以我把它切换到了这个并且效果更好.问题是快递接管了路由(从我能说的)
var options = {
// pathnameOnly: true,
router: {
'localhost': 'localhost:8080',
'localhost/blog': 'localhost:2368'
}
}
// Setup prox to handle blog requests
var proxyServer = httpProxy.createServer(options);
proxyServer.listen(9000);
require('./app/server/router')(app);
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
Run Code Online (Sandbox Code Playgroud)
Cha*_*ler 38
使用带有express的http-proxy 1.0:
var httpProxy = require('http-proxy');
var apiProxy = httpProxy.createProxyServer();
app.get("/api/*", function(req, res){
apiProxy.web(req, res, { target: 'http://google.com:80' });
});
Run Code Online (Sandbox Code Playgroud)
一个非常简单的解决方案,无缝地工作,并使用cookie /身份验证,使用express-http-proxy:
var proxy = require('express-http-proxy');
var blogProxy = proxy('localhost/blog:2368', {
forwardPath: function (req, res) {
return require('url').parse(req.url).path;
}
});
Run Code Online (Sandbox Code Playgroud)
然后简单地说:
app.use("/blog/*", blogProxy);
Run Code Online (Sandbox Code Playgroud)
我知道我参加这个派对已经很晚了,但我希望这对某人有所帮助.
我得到了这个工作。
npm install http-proxy为 /blog* 创建通配符路由,代理对 Ghost 服务的请求
var httpProxy = require('http-proxy');
var proxy = new httpProxy.RoutingProxy();
app.get('/blog*', function (req, res, next) {
proxy.proxyRequest(req, res ,{
host: 'moserlap.splitvr.com',
port: 2368
});
});
Run Code Online (Sandbox Code Playgroud)更新 Ghost 配置以使用子目录(仅在 0.4.0+ 中支持)
config = {
// ### Development **(default)**
development: {
// The url to use when providing links to the site, E.g. in RSS and email.
url: 'http://127.0.0.1/blog',
...
Run Code Online (Sandbox Code Playgroud)您现在应该能够访问http://yoursite.com/blog并且所有路由都有效。
| 归档时间: |
|
| 查看次数: |
29288 次 |
| 最近记录: |