混淆网络的应用程序接口 [英] Confusion about web-application ports
问题描述
我有一个项目,是在发展中已经深了,有问题的端口。
I have a project that is already deep in development, and there is a problem with the ports.
在客户端写SPA骨干,使用帆作为服务器。
The Client is SPA written in backbone, that uses Sails as a server.
问题是在客户端在Ex preSS运行在端口80上的事实,而帆船是在1337上运行。
Problem is in the fact that Client is running in Express on port 80, while Sails is run on 1337.
我想在帆内举办这次骨干应用,而不是ouside帆。
多一点细节:
当我火的提琴手,我看到被要求到本地主机发:1337 /得/用户。
我需要它驻留在80端口。
I would like to host this backbone application within the Sails, not ouside the sails. A bit more details: When I fire the Fiddler, I am seeing requests being made to localhost:1337/get/user. I need it to reside on port 80 as well.
骨干使用标准写入。我有app.js和main.js与所有常用文件夹(JS,LIBS,CSS)的。换句话说,我有了用require.js数据主要的index.html ...
Backbone is written using standard. I have app.js and main.js with all of the common folders (JS, LIBS, CSS). In other words, I have index.html that has data-main using require.js...
我在运行在单独的Node.js客户端没有问题......如何在Sails.js运行呢?
I have not problems running the client in separate node.js... how to run it within Sails.js?
我在哪里把我的index.html?
Where do I put my index.html???
推荐答案
试图服务 index.html的
作为一个静态文件将无法正常工作。相反,请尝试以下操作:
Trying to serve index.html
as a static file won't work. Instead, try the following:
1。服务您的 index.html的
从帆
1. Serve your index.html
from Sails
刚刚成为 index.html的
作为组合的意见/ layout.ejs
和意见的/ home / index.ejs
,它被安装到根 /
默认新建项目帆
Just serve index.html
as a combination of views/layout.ejs
and views/home/index.ejs
, which are mounted to the root /
for default newly created Sails project.
2。建立一个包罗万象的路线
在配置/ routes.js
把这样的事情:
module.exports.routes = {
'/': {
view: 'home/index'
},
'/:unknownRoute': {
view: 'home/index'
}
}
这样,您就可以,例如,你的SPA中使用简单的单级路由pushState的:像路由/产品
或 /新闻
仍将给你 index.html的
(如果你使用的是更复杂的东西,虽然,你可能想打多一点点带你的帆路由)。
This way you'll be able, for example, to use simple one-level pushstate routing within your SPA: routes like /products
or /news
will still give you your index.html
(if you are using something more complex though, you may want to play a little bit more with your Sails routes).
3。以$ P $满足您的API PFIX
在你的配置/ controllers.js
放,例如:
module.exports.controllers = {
...
prefix: '/api',
...
}
这会让你为你的API以preFIX,并且都 / API /产品
(JSON API)和 /产品
(您的SPA)提供的路线
This will let you serve your API with a prefix and have both /api/products
(JSON API) and /products
(your SPA) routes available.
4。使用任何你想要的端口
您可以通过配置/ local.js
更改默认端口,甚至到 80
如果你不('吨有任何其他关于 80
运行,当然)。
You can change the default port via config/local.js
, even to 80
(if you don't have anything else running on 80
, of course).
在生产,虽然,它很可能是只代理默认帆或任何其他端口Nginx的,例如一个更好的主意。
In production though, it would probably be a better idea to just proxy to default Sails' or any other port with Nginx, for example.
这篇关于混淆网络的应用程序接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!