我正在使用Rails作爲我的API,AngularJS在前端,而且我有一些問題正在使livereload/grunt連接代理正常工作。Grunt Livereload + Grunt連接代理
這裏是我的gruntfile片斷:
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost',
livereload: 35729
},
proxies: [
{
context: '/api',
host: 'localhost',
port: 3000
}
],
livereload: {
options: {
open: true,
base: [
'.tmp',
'<%= yeoman.app %>'
],
middleware: function (connect, options) {
var middlewares = [];
var directory = options.directory || options.base[options.base.length - 1];
// enable Angular's HTML5 mode
middlewares.push(modRewrite(['!\\.html|\\.js|\\.svg|\\.css|\\.png$ /index.html [L]']));
if (!Array.isArray(options.base)) {
options.base = [options.base];
}
options.base.forEach(function(base) {
// Serve static files.
middlewares.push(connect.static(base));
});
// Make directory browse-able.
middlewares.push(connect.directory(directory));
return middlewares;
}
}
},
test: {
options: {
port: 9001,
base: [
'.tmp',
'test',
'<%= yeoman.app %>'
]
}
},
dist: {
options: {
base: '<%= yeoman.dist %>'
}
}
}
如果我咕嚕建立「一切完美 - 關localhost:3000
但是,如果我的呼嚕聲服務」它通過127.0.0.1:9000
,我打開了一扇窗獲取404給我所有的API調用。
此外,根據服務它是從一個CSS文件重整我的背景圖像我得到這樣的警告:
Resource interpreted as Image but transferred with MIME type text/html: "http://127.0.0.1:9000/images/RBP_BG.jpg"
我以前沒有做過這一點 - 因此機會是我做這一切是錯誤的。
感謝您發佈此示例代碼咕嚕,連接代理 –
你救我一命的傢伙! –