Как устранить ошибку 404 из неправильно настроенных параметров grunt-connect-proxy в Gruntfile.js?
Фон:
Я пытаюсь подключить свой экземпляр сервера grunt к моей службе API, работающей на той же машине по адресу localhost:8080/api/.
В настоящее время для достижения этой цели используется grunt-connect-proxy.
Проблема / Вопрос:
http://localhost:9000/api/user-profile/ Failed to load resource: the server responded with a status of 404 (Not Found)
Есть ли ошибка с моим конфигом (ниже), которая мешает /api
запрос от перенаправления на прокси-сервер на localhost:8080?
Мои настройки (Gruntfile.js):
var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;
...
// Grunt configuration
grunt.initConfig({
// Project settings
someApp: appConfig,
// The grunt server settings
connect: {
options: {
port: 9000,
hostname: 'localhost',
livereload: 35729
},
server: {
proxies: [
{
context: '/api',
host: 'localhost',
port: 8080,
changeOrigin: true
}
]
},
livereload: {
options: {
open: true,
middleware: function (connect) {
return [
proxySnippet,
connect.static('.tmp'),
connect().use(
'/bower_components',
connect.static('./bower_components')
),
connect.static(appConfig.app),
];
}
}
},
main: {
options: {
open: true,
base: '<%= homer.main %>'
}
}
}
...
grunt.registerTask('live', [
'clean:server',
'copy:styles',
'configureProxies',
'connect:livereload',
'watch'
]);
grunt.registerTask('server', [
'build',
'connect:main:keepalive'
]);
1 ответ
Решение
Укажите цель подключения (в данном случае "сервер") в задаче configureProxies.
grunt.registerTask('live', function (target) {
grunt.task.run([
'clean:server',
'copy:styles',
'configureProxies:server',
'connect:livereload',
'watch'
]);
});