我有一个 yeoman angular 应用程序,我的配置grunt-connect-proxy
如下Gruntfile.js
:
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-connect-proxy');
[...]
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost',
livereload: 35729
},
dev: {
proxies: [
{
context: '/api/v1',
host: '127.0.0.1',
port: 3000,
https: false,
}
]
},
pro: {
appendProxies: false,
proxies: [{
context: '/api',
host: 'example.org'
}]
},
livereload: {
options: {
open: true,
middleware: function (connect) {
return [
require('grunt-connect-proxy/lib/utils').proxyRequest,
connect.static('.tmp'),
connect().use(
'/bower_components',
connect.static('./bower_components')
),
connect().use(
'/app/styles',
connect.static('./app/styles')
),
connect.static(appConfig.app)
];
}
}
},
test: {
options: {
port: 9001,
middleware: function (connect) {
return [
connect.static('.tmp'),
connect.static('test'),
connect().use(
'/bower_components',
connect.static('./bower_components')
),
connect.static(appConfig.app)
];
}
}
},
dist: {
options: {
open: true,
base: '<%= yeoman.dist %>'
}
}
},
[...]
grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'connect:dist:keepalive']);
}
grunt.task.run([
'clean:server',
'wiredep',
'concurrent:server',
'postcss:server',
'configureProxies:dev',
'connect:livereload',
'watch'
]);
});
grunt.registerTask('build', [
'clean:dist',
'configureProxies:pro',
'wiredep',
'useminPrepare',
'concurrent:dist',
'postcss',
'ngtemplates',
'concat',
'ngAnnotate',
'copy:dist',
'cdnify',
'cssmin',
'uglify',
'filerev',
'usemin',
'htmlmin'
]);
我在角度控制台中得到了这个:
Running "configureProxies:dev" (configureProxies) task
Proxy created for: /api/v1 to 127.0.0.1:3000
我的资源:
'use strict';
/**
* @ngdoc service
* @name doMasApp.Client
* @description
* # Client
* Service in the doMasApp.
*/
angular.module('doMasApp')
.factory('Client', [
'$resource',
function ($resource) {
var client = $resource(
'/clients/:id',
{ id: '@id' },
{
query: { isArray: false },
update: { method: 'PUT' }
});
return client;
}])
;
但是当我尝试连接到服务器并获取资源时,我得到了这个:
GET http://localhost:9000/clients 404 (Not Found)
请帮忙!!!