Grunt 连接代理:404 未找到

     2023-02-19     227

关键词:

【中文标题】Grunt 连接代理:404 未找到【英文标题】:Grunt Connect Proxy: 404 Not Found 【发布时间】:2016-06-16 04:18:15 【问题描述】:

我正在使用 grunt-connect-proxy "^0.2.0" 从我的 angularjs 应用程序代理到 api。该项目是从 yeoman angular-generator 开始的。

我已经按照here 的说明进行操作,但是当使用代理时,我得到:

Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:9000/api/users 

我的代理配置:

 connect: 
  options: 
    port: 9000,
    // Change this to '0.0.0.0' to access the server from outside.
    hostname: 'localhost',
    livereload: 35729
  ,
  proxies: [
    context: '/api', // the context of the data service
    host: 'localhost', // wherever the data service is running
    port: 8080, // the port that the data service is running on
    https: false,
    xforward: false
  ],

我的中间件:

livereload: 
    options: 
      open: true,
      base: '',
      middleware: function (connect, options) 
        var middlewares = [];

        middlewares.push(require('grunt-connect-proxy/lib/utils').proxyRequest);

        middlewares.push(connect.static('.tmp'));
        middlewares.push(connect.static('test'));
        middlewares.push(connect().use(
            '/bower_components',
            connect.static('./bower_components')
          ));
        middlewares.push(connect.static(appConfig.app));

        return middlewares;
      
    
  ,

我的服务任务

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',
    'autoprefixer:server',
    'configureProxies:server',
    'connect:livereload',
    'watch'
  ]);
);

编辑 localhost:8080/users 当前通过 Postman 返回 403,因此 API 正在运行。

【问题讨论】:

您是否在选项之前尝试使用 server: ? 看看这个问题..也许会有所帮助***.com/questions/34321143/… 【参考方案1】:

我遇到了同样的问题,我用这种方式解决了它,它对我有用。在下面查看我的代码:-

connect:  
            server:  
                options:  
                    keepalive: true, 
                    port: 8001, 
                    protocol: 'http', 
                    hostname: '*', 
                    directory: 'dist', 
                    open:  
                        target: 'http://localhost:8001/myDemo.html', 

                    ,
                        middleware: function(connect, options, middlewares) 

                                middlewares.unshift(function(req, res, next) 
                                    res.setHeader('Access-Control-Allow-Credentials', true);
                                    res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
                                    res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
                                    **if (req.method.toUpperCase() == 'POST') req.method='GET';**
                                    return next();
                                );

                                return middlewares;
                        

                 
             
        ,

见星标行,即 if (req.method.toUpperCase() == 'POST') req.method='GET';我做了这个把戏,它对我有用。这篇文章对我也有帮助https://github.com/gruntjs/grunt-contrib-connect#middleware

【讨论】:

【参考方案2】:

不直接回答您的问题,而是提供解决方案(因为没有其他人回答过)...您是否尝试过 npm 模块 connect-modrewrite

这正是你想要做的。

【讨论】:

未找到404的springwebsocket

...尝试用spring创建一个websocket端点。但每当我尝试从客户端连接时,我得到404.我也有一个Java实现@ServerEndpoint(value="/websocket")这很好用。下面是我的spring实现的代码,它不起作用。我在这做错了什么?packagecom.tlab.endpoint;importorg.spring... 查看详情

在远程服务器上配置 codeigniter(404 未找到)

...我完成了所有配置,我仍然有(404未找到)。与服务器的连接正常,我可以上传文件。在$config[\'base 查看详情

GET http://js:port/socket.io/1/ 404 未找到

】GEThttp://js:port/socket.io/1/404未找到【英文标题】:GEThttp://js:port/socket.io/1/404notfound【发布时间】:2014-01-1606:24:47【问题描述】:Socket.io无法连接。这是我的服务器代码:functionchatserver()varexpress=require(\'express\'),app=express(),server=requir 查看详情

邮递员:“状态”:404,“错误”:“未找到”,“消息”:“未找到”,

】邮递员:“状态”:404,“错误”:“未找到”,“消息”:“未找到”,【英文标题】:Postman:"status":404,"error":"NotFound","message":"NotFound",【发布时间】:2020-08-0502:33:05【问题描述】:@RestC... 查看详情

带有 http-bind 的 strophe.js 无法加载资源 404 未找到

...:2015-08-2414:45:20【问题描述】:我正在尝试使用strophe.js连接ejabberd服务器,但出现以下错误:POSThttp://localhost/http-bind/404(NotFound)Strophe.B 查看详情

404 未找到有效 url 的错误

】404未找到有效url的错误【英文标题】:404notfounderrorforvalidurl【发布时间】:2016-11-0206:23:20【问题描述】:afnetworking得到404未找到有效url。相同的网址在邮递员中运行良好。AFHTTPRequestOperationManager*manager=[AFHTTPRequestOperationManagermana... 查看详情

当主机更改源时,grunt karma 对 vagrant 进行测试 grunt/karma 未检测到它

...间】:2014-07-0710:04:30【问题描述】:这花了我很长时间才找到,但似乎无法找到解决方案。使用vagrant我运行了一个运行grunt/karma的Fedora 查看详情

错误 404 - 未找到 Wildfly

】错误404-未找到Wildfly【英文标题】:Error404-NotFoundWildfly【发布时间】:2018-05-0320:00:48【问题描述】:我在浏览器中运行XHTML页面时出错。在Wildfly10.0中运行时出现“错误404-未找到”我已经尝试了所有方法,但仍然出现错误。这... 查看详情

TestServer 返回 404 未找到

】TestServer返回404未找到【英文标题】:TestServerreturns404notfound【发布时间】:2019-08-1504:12:12【问题描述】:我正在为我的webapi项目使用aspnetcore3.0preview7。目前我正在实施集成测试。(首先为了让测试更容易,我注释掉了控制器上... 查看详情

ruby404未找到(代码片段)

查看详情

本地主机:404 未找到

】本地主机:404未找到【英文标题】:Localhost:404notfound【发布时间】:2013-07-2203:29:22【问题描述】:我正在使用XAMPP。和Django的内部服务器。当我浏览到localhost或127.0.0.1时,它显示NotFound.HTTPError404.Therequestedresourceisnotfound.它有时... 查看详情

CodeIgniter 404 页面未找到,但为啥?

】CodeIgniter404页面未找到,但为啥?【英文标题】:CodeIgniter404PageNotFound,butwhy?CodeIgniter404页面未找到,但为什么?【发布时间】:2011-04-1417:38:34【问题描述】:我将CodeIgniter用于两个应用程序(一个公共应用程序和一个管理应用... 查看详情

未找到 Apache 虚拟主机 404

】未找到Apache虚拟主机404【英文标题】:Apachevirtualhost404notfound【发布时间】:2015-06-2222:43:33【问题描述】:我刚开始学习php,我正在尝试使用XAMPP在本地托管我自己的php网站。我想创建虚拟主机:网址:myphpwebsite.local端口:8088... 查看详情

Laravel API 路由 404 未找到修复?

】LaravelAPI路由404未找到修复?【英文标题】:LaravelAPIroutes404notfoundfix?【发布时间】:2022-01-1410:10:05【问题描述】:我刚刚上传了仅用于API的Laravel后端项目,但是当我从邮递员那里调用任何路由时,它显示404未找到,我无法捕捉... 查看详情

Codeigniter - 404 页面未找到

】Codeigniter-404页面未找到【英文标题】:Codeigniter-404PageNotFound【发布时间】:2015-07-2822:16:09【问题描述】:我正在使用Codeigniter。一切都很好,直到我创建名为user_authentication.php的新控制器(位于http://localhost/etalasekursusci/index.php/u... 查看详情

Spring-Boot MVC 模板未加载(未找到 404)

】Spring-BootMVC模板未加载(未找到404)【英文标题】:Spring-BootMVCTemplateNotLoading(404NotFound)【发布时间】:2015-01-0320:05:11【问题描述】:我在这里有一个非常简单的Spring-BootMVC应用程序,但它不工作。一个控制器,一个页面未加载... 查看详情

Wordpress 联系表(未找到 404)

】Wordpress联系表(未找到404)【英文标题】:Wordpresscontactform(404notfound)【发布时间】:2014-12-0512:10:08【问题描述】:我在WordPress上创建了一个模板并制作了一个html表单。它在HTML中运行良好,但在WordPress上使用时不起作用。它似... 查看详情

错误 404.3 未找到 JSON 文件

】错误404.3未找到JSON文件【英文标题】:ERROR404.3NotFoundforJSONfile【发布时间】:2013-04-1108:43:06【问题描述】:即使在激活所有“应用程序开发功能”之后,我在“Internet信息服务7.5”上使用AJAX调用调用的JSON文件也收到“错误404.3... 查看详情