从极加载angularjs REST资源时,漫长的等待时间 [英] Extremely long wait time when loading REST resource from angularjs

查看:215
本文介绍了从极加载angularjs REST资源时,漫长的等待时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个前端的角度正在访问一个烧瓶/蟒蛇的RESTful API。 我使用AngularJS v1.2.16。

I'm building a front-end in angular that is accessing a flask/python RESTful API. I'm using AngularJS v1.2.16.

由于某些原因,它需要之前REST资源被加载后,大部分时间只是等待的时间疯狂量。这是我的理解是等待的测量时间第一个字节 - 我的所有服务在本地运行(前端,API和数据库)。

For some reason, it takes an insane amount of time before the REST resource is loaded, with most of the time just waiting. It's my understanding that 'waiting' is measuring the time to first byte - all my services run locally (the frontend, API and database).

考虑到服务的所有本地运行,我很茫然如何调试此。是否有人有对在哪里看什么秘诀?我检查了所有我的方法和他们体面跑得快(100毫秒下每股REST调用)。当我使用<一个href=\"https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?hl=en\">postman, API返回近乎瞬间。

Given that the services all run locally, I am at a loss how to debug this. Does anybody have any tips on where to look? I checked all my methods and they run decently fast (under 100ms per REST call). When I use postman, the API returns near-instantly.

任何想法如何解决等,似乎只有通过加载角基于REST的资源的时候是这样的。角$ HTTP GET请求是相当简单的:

Any ideas how to fix the wait, it only seems to be the case when loading the RESTful resource via angular. The angular $http get request is fairly straight forward:

myAppControllers.controller('ManageCtrl', ['$scope', '$http',
    function($scope, $http) {
        $http({
            url: 'http://127.0.0.1:5000/v1/domains/',
            method: "GET",
            headers: { 'Content-Type': 'application/json' },
        }).
        success(function(data, status, headers, config) {
            console.log('login successful');
            console.log(status);
            console.log(data);
        }).
        error(function(data, status, headers, config) {
            console.log('login failed');
        });
    }]);

编辑:


  • 这个问题只出现在谷歌Chrome,常规模式。

  • 的GET请求使用隐身模式时快。

推荐答案

我碰到同样的问题(前端角在Chrome和烧瓶后台运行)。试图既角的1.2.x和1.3.x中,和其他十亿排列后,唯一的解决方案,我发现是运行瓶后端与龙卷风网络服务器(的http://www.tornadoweb.org/en/stable/ )。其他WSGI容器可以工作,但是这是我测试过的人。

I've run into the same issue (Angular frontend running in Chrome and Flask backend). After trying both Angular 1.2.x and 1.3.x, and a billion other permutations, the only "solution" I've found is to run the Flask backend with the Tornado web server (http://www.tornadoweb.org/en/stable/). Other WSGI containers may work, but this is the one I tested.

在您的应用程序瓶,粘贴以下内容:

In your Flask application, paste the following:

from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop

if __name__ == '__main__':
  http_server = HTTPServer(WSGIContainer(app))
  http_server.listen(5000)
  IOLoop.instance().start()

您可以通过键入启动Web服务器:

You can start your web server by typing:

python myserver.py

这篇关于从极加载angularjs REST资源时,漫长的等待时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆