Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

node.js - Can't reach firestore from server.ts in Angular 8 application

I need to create RSS feed in my Angular 8 + Firebase app but i'm receiving discarding entity body for GET requests warning in console. And after pending request data is []

server.ts

app.get('/feed', function(req, res) {
  const query = db.collection('news').orderBy('orderId').limit(3);
  const filteredNews = [];
  query.get().then(posts => {
    posts.forEach(item => {
      filteredNews.push(item.data());
    });
    return filteredNews;
  }).then(data => {
    const feedOptions = {
      title: 'title',
      description: 'description',
      feed_url: 'https://barvy.today/rss.xml',
      site_url: 'https://barvy.today',
      image_url: 'https://barvy.today/assets/images/favicon.ico',
      language: 'ua',
      pubDate: data[0].utcDate,
    };
    const feed = new RSS(feedOptions);
    data.forEach((item) => {
        feed.item({
            title: item.headingUa,
            description: item.data[0].dataUa,
            url: item.rssLink,
            guid: item.id,
            date: item.utcDate,
            enclosure: { url: item.mainImg.url.toString().replace('&', '&'), type: 'image/jpeg' }
        });
    });
    const xml = feed.xml({ indent: true });
    res.set('Content-Type', 'text/xml');
    res.send(xml);
  });
});

webpack.config.js

const regex = /firebase/(app|firestore)/;
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  mode: 'none',
  entry: {
    server: './server.ts'
  },
  externals: {
    './dist/server/main': 'require("./server/main")'
  },
  target: 'node',
  resolve: {
    extensions: ['.ts', '.js']
  },
  optimization: {
    minimize: false
  },
  output: {
    // Puts the output at the root of the dist folder
    path: path.join(__dirname, 'dist'),
    filename: '[name].js'
  },
  module: {
    noParse: /polyfills-.*.js/,
    rules: [
      { test: /.ts$/, loader: 'ts-loader' },
      {
        test: /(\|/)@angular(\|/)core(\|/).+.js$/,
        parser: { system: true },
      },
    ]
  },
  plugins: [
    new webpack.ContextReplacementPlugin(
      /(.+)?angular(\|/)core(.+)?/,
      path.join(__dirname, 'src'),
      {}
    ),
    new webpack.ContextReplacementPlugin(
      /(.+)?express(\|/)(.+)?/,
      path.join(__dirname, 'src'),
      {}
    )
  ]
};

With firebase-admin app is not even building

question from:https://stackoverflow.com/questions/65944099/cant-reach-firestore-from-server-ts-in-angular-8-application

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...