我已经编写了一些云函数并部署了它们,现在我正在尝试使用我的 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) 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) 我正在使用 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文件的方法 …
我正在 firestore auth 中动态创建用户,并添加了多种类型的声明,即管理员、讲师、助理。到目前为止admin: true,instructor: 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) angular ×3
node.js ×2
angularfire ×1
cors ×1
exceljs ×1
firebase ×1
javascript ×1
oauth ×1
rxjs ×1
typescript ×1