(如果需要,请参阅我的上一个问题以获取更多背景信息.)
我正在开发一个使用分离的前端和后端的应用程序:
localhost:3000),主要提供REST API.localhost:3001.为了让两端相互通信,同时尊重同源策略,我将nginx配置为两者之间的代理,可用localhost:3002.这是我的nginx.conf:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 3002;
root /;
# Rails
location ~ \.(json)$ {
proxy_pass http://localhost:3000;
}
# AngularJS
location / {
proxy_pass http://localhost:3001;
}
}
}
Run Code Online (Sandbox Code Playgroud)
基本上,.json我发送到Rails服务器的任何文件请求,以及任何其他请求(例如,对于静态资产),我都要发送到BrowserSync服务器.
我的BrowserSync任务gulpfile.coffee:
gulp.task 'browser-sync', ->
browserSync
server:
baseDir: './dist'
directory: true
port: 3001
browser: 'google chrome' …Run Code Online (Sandbox Code Playgroud)