【问题标题】:Meteor react publish raw json流星反应发布原始json
【发布时间】:2017-03-07 15:41:04
【问题描述】:

我正在尝试抓取我自己的流星反应应用程序。

但是,当我在“http://localhost:3000/export_json”上有一个简单的 json 时,它会发布:

{"greetings": "hello"}

使用 Python 3,我尝试使用 urlopen 阅读内容:

url = "http://localhost:3000/export_json"
html = urllib.request.urlopen(url)
html.read()

我得到一整页而不是 json:

b'<!DOCTYPE html>\n<html>\n<head>`\n  <link rel="stylesheet" type="text/css" class="__meteor-css__" href="/merged-stylesheets.css?hash=a899d6ca37c7cf0b13ba96f881073946529354d0">\n<title>\n    ThisIsMyTitle\n  </title>\n\n</head>\n<body>\n\n\n\n<script type="text/javascript">__meteor_runtime_config__ = JSON.parse(decodeURIComponent ...`

这可能与 Meteor+react 的反应性有关,但我不知道如何绕过它。

【问题讨论】:

    标签: python-3.x meteor


    【解决方案1】:

    您不能发布纯 JavaScript 对象。您必须发布cursor

    您想要创建一个method,并在连接到您的端点时使用它,使用Pickersimple:json-routes 等工具。有关更多示例和方法,请参阅 Meteorpedia

    JsonRoutes.add("get", "/posts/:id", function (req, res, next) {
      var id = req.params.id;
    
      JsonRoutes.sendResult(res, {
        data: Posts.findOne(id)
      });
    });
    

    【讨论】:

    • 这很有帮助!但不幸的是,Picker 工具不适用于 react-router。 Meteor+react 和react-router 有解决方案吗?
    • 这解决了我的问题! stackoverflow.com/questions/32462946/… 但你的建议帮助我朝着正确的方向前进
    • 不错!仅供参考,我检查了我过去做过的一个项目,我使用了simple:json-routes。我认为这进一步抽象了webapp 包,它真的很容易使用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-18
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多