【问题标题】:Display RSS Feed or API on Vue application在 Vue 应用程序上显示 RSS Feed 或 API
【发布时间】:2020-01-20 15:51:18
【问题描述】:

我已经尝试了几个月了。

我希望在我的 vue.js 应用程序上显示以下 RSS 提要:https://www.google.ie/alerts/feeds/10663948362751557705/4511034072220974544

但是如何将以下所有内容链接在一起并显示系列文章?我在这里挣扎,任何帮助将不胜感激!

我已经设置了一个后端来避免 Express.js 中的 CORS 策略:

const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const morgan = require('morgan');

const app = express();

app.use(morgan('tiny'));
app.use(cors());
app.use(bodyParser.json());

app.get('/', (req, res) => {
    res.json({
        message: 'Test'
    });
});

const port = process.env.PORT || 4000;
app.listen(port, () => {
    console.log(`listening on ${port}`);
});

GoogleAlert 组件:

<template>
  </template>

<script>
  export default {

  };
</script>

PostArticles.js:

import axios from 'axios';

const url = 'http://localhost:4000';

export default {
mounted() {
  axios.get('https://www.google.ie/alerts/feeds/10663948362751557705/16000017647453347583')
  .then(function (response) {
    // handle success
  console.log(response);
  })
 .catch(function (error) {
    // handle error
   console.log(error);
 });
}

【问题讨论】:

    标签: javascript api express vue.js rss


    【解决方案1】:

    您的后端使用 CORS 允许任何来源从中读取数据。

    您的前端正在直接从 Google 请求 RSS 数据。它不会靠近您的后端。

    Google 没有使用 CORS 来授予您的前端读取其数据的权限。

    您需要更改您的前端,以便它向您的后端询问数据,并且您需要更改您的后端,以便它为前端提供该数据(这意味着让后端从 Google 获取数据(并且可能保留一个本地它的缓存))。

    【讨论】:

    • 谢谢。问题是我不知道该怎么做。
    • 正如@Quentin 建议的那样,您的节点代码必须向 Google 发出请求,然后输出结果。您可以通过各种方式在 Node 中使用 HTTP,我建议使用 node-fetch,但最后,您希望能够访问 Node 代码的 URL 并确保它输出 RSS。完成后,您的前端将指向 Node 服务器的 URL。基本上 - 研究如何在 Node 中发出 HTTP 请求,相当简单,然后你就基本完成了。 :)
    猜你喜欢
    • 2012-11-18
    • 2021-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多