rails和node.js之间的路由
在rails中,我用paperclip + resque上传和处理图像,消耗太多内存,速度很慢。 我想尝试node.js在后台处理这些东西。
是可能的路线轨道和node.js都具有相同的端口?
一些路由处理rails,一些路由到node.js。 例如,
轨道
/users/:user_id/albums(.:format) /users/:user_id/albums/new(.:format) /users/:user_id/albums/:id/edit(.:format)
的node.js
/uploads
谢谢。
解决scheme
POST /上传到node.js(端口8080)来处理其他的rails。 下面是我的nginx conf
location = /uploads { proxy_pass http://127.0.0.1:8080/uploads; } location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri/index.html $uri @unicorn; location @unicorn { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://unicorn; }
谢谢@Matthew Ratzloff
就是这样。 您可以使用反向代理,并将selectpath转发到您的Node.js服务器和其他人到您的Rails应用程序。
- 的httpd
- nginx的
现在,这是一个好主意吗? 好…
一个更好的解决scheme是继续从Rails的Resque中创build工作,但使用像Coffee-Resque这样的工具来实际处理工作。 这就是我要走的路线。
希望有所帮助!
No; 10.times { No }
但。 假设你想这样做。 你会:
- 将文件直接上传到S3
- 向Node发出一个请求来下载和处理文件
- 完成后,向Rails发送一个HTTP请求,用文件属性更新其数据库。