Untitled
unknown
plain_text
2 years ago
1.6 kB
5
Indexable
/** * Import function triggers from their respective submodules: * * import {onCall} from "firebase-functions/v2/https"; * import {onDocumentWritten} from "firebase-functions/v2/firestore"; * * See a full list of supported triggers at https://firebase.google.com/docs/functions */ import {onRequest} from "firebase-functions/v2/https"; import * as logger from "firebase-functions/logger"; import { initializeApp } from "firebase-admin/app"; import * as corsLib from "cors"; import dayjs = require("dayjs"); var utc = require('dayjs/plugin/utc') var timezone = require('dayjs/plugin/timezone') // dependent on utc plugin dayjs.extend(utc) dayjs.extend(timezone) const tz = "America/New_York" const dayjsLocal = dayjs(); //assumes UTC const dayjsAmerica = dayjsLocal.tz(tz) //existing time treated as UTC const dayjsAmericaKeep = dayjsLocal.tz(tz, true) //existing time treated as local time const cors = corsLib({ origin: (origin, callback) => { // Allow requests from localhost (you can add more conditions if needed) if (origin === "http://localhost" || origin === "http://localhost:5173") { //TODO: add hosting domain!!! callback(null, true); } else { // Deny requests from other origins callback(new Error("Not allowed by CORS")); } }, }); initializeApp(); export const helloWorld = onRequest((request, response) => { cors(request, response, async () => { logger.info("Hello logs!", {structuredData: true}); console.log('first', dayjsFinland) response.send("Hello from Firebase!!!"); }); });
Editor is loading...