转发咕噜连接到不同的网址

编程入门 行业动态 更新时间:2024-10-28 16:18:38
本文介绍了转发咕噜连接到不同的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我希望能够调用位于/server.

要做到这一点,我需要从

http:// localhost:9000 / server

www.production-server/server

这对我有好处,因为有时我想在开发模式下测试生产服务器。

这是我目前的连接配置(由Yeoman生成):

connect:{options:{port:9000,//将其更改为'0.0.0.0'以访问外面的服务器。主机名: '本地主机',livereload:35729},livereload:{选择:{开:真,中间件:功能(连接,期权,中间件){返回[connect.static( 'TMP'。),连接()使用(。 '/ bower_components',connect.static('./ bower_components')),connect.static(appConfig.app)]; ();}}},test:{options:{port:9001,middleware:function(connect){return [connect.static('。tmp'),connect.static('test'),connect bower_components',connect.static('./ bower_components')),connect.static(appConfig.app)]; }}} dist:{options:{open:true,base:'<%= yeoman.dist%>'}}},

$ b $我发现了这个问题和解决方案: 首先要做的是使用:grunt-connect-proxy grunt任务来完成代理(你可以在那里做任何事情)。配置不明显,但您可以在此处找到所有信息(和示例): https://www.npmjs / package / grunt-connect-proxy

我的具体问题是因为我的服务器不接受来自同一个域的任何调用,所以我所做的只是添加标题属性到我的域名配置。这是新的配置应该是这样的:

connect:{ options:{ port: 9000, //将其更改为'0.0.0.0'以从外部访问服务器。 主机名:'localhost', livereload:35729 },服务器:{代理:[ { context:'/服务器',主机:'production-server',发布:80, changeOrigin:true,标题:{主机:'simple-layout '} } ] }, livereload:{ options:{ open:true,中间件:函数(连接){返回[ proxySnippet, connect.static('。tmp'), connect()。use('/ bower_components ', connect.static('./ bower_components') ), connect.static(appConfig.app)]; $ b test $ { options { port:9001, middleware:function(connect){ return [ connect.static('。tmp'), connect.static('test'), connect()。use('/ bower_components' , connect.static('./ bower_components')), connect.static(appConfig.app)]; } } }, dist:{选项:{ open:true, base:'<%= yeoman .dist%>'} } },

I'm using grunt connect with livereload for my dev environment.

I want to be able to call the production api which is under /server.

To do that I need to direct any calls from

localhost:9000/server

to

www.production-server/server

This is good for me because sometimes I want to test against the production server when in dev mode.

Here's my current connect configuration (Generated by Yeoman):

connect: { options: { port: 9000, // Change this to '0.0.0.0' to access the server from outside. hostname: 'localhost', livereload: 35729 }, livereload: { options: { open: true, middleware: function(connect, options, middlewares) { return [ connect.static('.tmp'), connect().use( '/bower_components', connect.static('./bower_components') ), connect.static(appConfig.app) ]; } } }, test: { options: { port: 9001, middleware: function(connect) { return [ connect.static('.tmp'), connect.static('test'), connect().use( '/bower_components', connect.static('./bower_components') ), connect.static(appConfig.app) ]; } } }, dist: { options: { open: true, base: '<%= yeoman.dist %>' } } },

解决方案

I've found the problem and the solution:

First thing to do is to use the: grunt-connect-proxy grunt task to be able to do proxy (You can do really anything there). The configuration is not obvious, but you can find all the info (and example) here: www.npmjs/package/grunt-connect-proxy

My specific problem was because my server did not accept any calls that did not come from the same domain, so all I did was to add "headers" property to the config with my domain name. this is how the new config should look like:

connect: { options: { port: 9000, // Change this to '0.0.0.0' to access the server from outside. hostname: 'localhost', livereload: 35729 }, server: { proxies: [ { context: '/server', host: 'production-server', post: 80, changeOrigin: true, headers: { host: 'simple-layout' } } ] }, livereload: { options: { open: true, middleware: function (connect) { return [ proxySnippet, connect.static('.tmp'), connect().use( '/bower_components', connect.static('./bower_components') ), connect.static(appConfig.app) ]; } } }, test: { options: { port: 9001, middleware: function (connect) { return [ connect.static('.tmp'), connect.static('test'), connect().use( '/bower_components', connect.static('./bower_components') ), connect.static(appConfig.app) ]; } } }, dist: { options: { open: true, base: '<%= yeoman.dist %>' } } },

更多推荐

转发咕噜连接到不同的网址

本文发布于:2023-10-31 19:28:00,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   网址

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!