LoginSignup
5
5

More than 5 years have passed since last update.

node-redでgoogle feed apiの様なもの

Last updated at Posted at 2016-01-17

概要

google feed apiで大騒ぎしたので、node-redでやってみました。

写真

proxy.jpg

func0

msg.url = msg.payload.url;
return msg;

func1

msg.res.header('Access-Control-Allow-Origin', '*');
msg.res.send(msg.payload);
return msg;

実行結果

feed.jpg

サンプルコード

function xmlLoad() {
    var rss_url = "http://rss.dailynews.yahoo.co.jp/fc/rss.xml"; 
    var proxy = "http:// node-red /proxy";
    $.ajax({
        url: proxy,
        type: 'get',
        dataType: 'xml',
        timeout: 5000,
        data: {
           url: rss_url
        },
        success: parse_xml
    });
}
function parse_xml(xml, status) {
    if (status != 'success') return;
    $(xml).find('item').each(disp);
}
function disp() {
    var $link = $(this).find('link').text();
    var $title = $(this).find('title').text();
    var $html = '<a href="' + $link + '"> ' + $title + '</a><br>';
    $('#result').append($html);
}
$(function() {
    xmlLoad();
});
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5