使用OS X SierraRails服务器错误不明确
我有一个rails应用程序,包含两个部分:前端和后端。 在后端我使用rails 4. 在前端我使用Angular。 无论何时我必须在本地启动服务器(用于开发或测试),我都使用3个不同的控制台窗口。
一个运行grunt watch
“
另一个运行http-server ./build/ -p 8000 -c-1
最后运行rails server
我的本地后端储存库只是一个什么是对生产运行的克隆。(减去服务器配置)
当我使用前端连接到我的远程服务器时,它没有问题,但是当我在本地运行后端并尝试登录时,以下日志,并没有任何反应:
=> Booting WEBrick
=> Rails 4.2.7 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2017-01-02 16:19:21] INFO WEBrick 1.3.1
[2017-01-02 16:19:21] INFO ruby 2.3.3 (2016-11-21) [x86_64-darwin15]
[2017-01-02 16:19:21] INFO WEBrick::HTTPServer#start: pid=10496 port=3000
前端引发以下错误:
XMLHttpRequest cannot load localhost:3000/auth_user? [email protected]&password=VVVVVVVV. Cross origin requests are only supported for HTTP.
我的角端点文件
angular.module('common.config', [])
.factory('endpoints', function() {
var host = 'development';
if (['live.companysite.com'].indexOf(window.location.host) > -1) {
host = 'production';
} else if (['companysite.com'].indexOf(window.location.host) > -1) {
host = 'development';
} else {
host = 'local';
}
var endpoints = {
'production': {
root: 'http://live.companysite.com/'
},
'development': {
root: 'http://companysite.com/'
},
'local': {
root: 'localhost:3000/'
}
};
return endpoints[host];
});
我知道,它应该是一个CORS问题,但因为它与两台远程服务器(生产和测试)完美协作,我相信我的本地配置可能是问题所在。
“本地主机:3000auth_user鄂麦?”我认为你缺少/ AUTH_USER前后:3000,检查在那里你在你的角度项目中定义的API行,也许你需要添加一个斜杠/ –
@HugoFarji固定的,但仍然得到相同的错误 – Anika
@HugoFarji原来我不得不把“http://”放在我的端点之前。现在不要现在我怎么错过了。谢谢! 现在我有: '本地':{ 根: “HTTP://本地主机:3000 /” } 您可以添加它作为一个答案,所以我能接受吗? – Anika