小编ahs*_*sar的帖子

在 Firebase Cloud Function 中启用 Cors

我已经编写了一些云函数并部署了它们,现在我正在尝试使用我的 Angular 应用程序访问这些 API,但出现此错误

从源“ http://localhost:4200 ”访问 XMLHttpRequest at 'xxxxxxxxxxxxxxxxxxxxxxxx'已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:不存在“Access-Control-Allow-Origin”标头在请求的资源上。

我知道我必须在我的云功能中启用 cors,但我以前从未这样做过,所以如果你们能告诉我如何做到这一点会很棒吗?我确实检查了这个线程,但我有点困惑我需要在哪里初始化 cors,我是否也需要安装它的依赖项,我需要在我的云功能中在哪里启用它?这是我的云功能

const functions = require('firebase-functions');


const admin = require("firebase-admin");

const bodyParser = require("body-parser");


admin.initializeApp();

const db = admin.firestore();

const usersCollection = db.collection("users");

exports.addUser = functions.https.onRequest((req, res) => {
    if (req.body.username != null && req.body.firstname != null && req.body.lastname != null && req.body.addr1 != null && req.body.addr2 != null || req.body.username != undefined && req.body.firstname != undefined && req.body.lastname != undefined && req.body.addr1 != undefined …
Run Code Online (Sandbox Code Playgroud)

node.js cors angular google-cloud-firestore

15
推荐指数
1
解决办法
2万
查看次数

ERROR TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable in Angular Services

I have written multiple services to hit different APIs. The services written for post are working somehow but giving this error

ERROR TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable. at subscribeTo (subscribeTo.js:27)

As for the services written for the GET method the same error is shown but i get no data in return. Here is my service

GetClientData(): Observable<ClientDto> {
    let url_ = this.baseUrl + "https://xxxxxxxxxxxxxxxx/getClients";
    url_ = url_.replace(/[?&]$/, …
Run Code Online (Sandbox Code Playgroud)

rxjs typescript angular

6
推荐指数
1
解决办法
8937
查看次数

ExcelJS 特定日期列下的数据

我正在使用 nodejs 应用程序中的 exceljs 包创建 Excel 工作表。我有一个像这样生成的标题数组。

const monthsArray = arrDays.map((str) => (
   { header: str, key: str, width: 10 } // Example { header: "12-15-2021", key: "12-15-2021", width: 10}
));

let headers = [
   { header: "Name", key: "Name", width: 10 },
   { header: "Phone", key: "Phone", width: 13 },
   { header: "CNIC", key: "CNIC", width: 13 },
   { header: "City", key: "City", width: 10 },
   ...monthsArray
];
Run Code Online (Sandbox Code Playgroud)

现在我正在运行一个聚合,它将返回用户记录,同时我将在其中获得一个嵌套对象,该对象将包含特定日期的出勤记录,例如这样createdAt: "2021-12-15T19:56:37.984Z"present: true。现在,我可以在第一行正确打印标题,每列顶部显示日期,在此之前打印上述数据,例如姓名、电话、城市等。但是我需要知道如何在正确的下显示正确的出勤记录柱子?这样,true 必须写在12-15-2021特定用户的列下。

这是我生成Excel文件的方法 …

javascript node.js exceljs

5
推荐指数
1
解决办法
1538
查看次数

使用自定义声明的 Angular 和 Firebase 路线守卫

我正在 firestore auth 中动态创建用户,并添加了多种类型的声明,即管理员、讲师、助理。到目前为止admin: trueinstructor: true根据我提供的登录凭据,我能够使用新创建的用户登录并获取 claim 属性为 true 。但是我无法[AuthGuard]在路由中正确设置,甚至没有登录我就可以使用 url 重定向到组件,这不应该发生。我对如何正确添加AuthGuard. 这是我的代码

auth-service.ts

import * as firebase from 'firebase/app';

import { AngularFireAuth } from '@angular/fire/auth';
import { AngularFirestore } from '@angular/fire/firestore';
import { Injectable } from '@angular/core';
import { JwtHelperService } from '@auth0/angular-jwt';
import { Observable } from 'rxjs/Observable';
import { Router } from "@angular/router";

@Injectable() 
export class AuthService {
public user: Observable<firebase.User>;
public userDetails: firebase.User = null;

constructor(private _firebaseAuth: AngularFireAuth, …
Run Code Online (Sandbox Code Playgroud)

oauth firebase angularfire angular google-cloud-firestore

4
推荐指数
1
解决办法
3691
查看次数