I have a flutter web app that I am running on localhost to debug, my web app posts data to my Firebase Cloud functions API which then sends data to Google Bigquery to create a table, although I have installed CORS already I keep getting this error in my browser below
Access to XMLHttpRequest at 'https://us-central1-denance-cbf3f.cloudfunctions.net/api/create_table' from origin 'http://localhost:55073' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
us-central1-denance-cbf3f.cloudfunctions.net/api/create_table:1 Failed to load resource: net::ERR_FAILED
errors.dart:202 Uncaught (in promise) Error: XMLHttpRequest error.
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 897:28 get current
packages/http/src/browser_client.dart 71:22 <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1687:54 runUnary
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 155:18 handleValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 707:44 handleValueCallback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 736:13 _propagateToListeners
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 533:7 [_complete]
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_pipe.dart 61:11 _cancelAndValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream.dart 1219:7 <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 324:14 _checkAndCall
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 329:39 dcall
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/html/dart2js/html_dart2js.dart 37324:58 <fn>
at Object.createErrorWithStack (:55073/dart_sdk.js:5070)
at Object._rethrow (:55073/dart_sdk.js:37715)
at async._AsyncCallbackEntry.new.callback (:55073/dart_sdk.js:37711)
at Object._microtaskLoop (:55073/dart_sdk.js:37568)
at _startMicrotaskLoop (:55073/dart_sdk.js:37574)
at :55073/dart_sdk.js:33324
this is my code below
const functions = require("firebase-functions");
const express = require('express');
var cors = require('cors');
const { BigQuery } = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
var app = express();
app.use(cors);
app.use(express.json());
exports.api = functions.https.onRequest(app);
app.post('/create_table', cors(dynamicCorsOptions), function (req, res,) {
'use strict';
async function createTable() {
let schema = [];
async function groupUp() {
for (let key in req.body) {
schema.push({ name: req.body[key]['name'], type: req.body[key]['type'] });
}
}
await groupUp();
await doingIt();
async function doingIt() {
var datasetId = 'denanse'; // Existing dataset
var tableId = 'hrhrhhh'; // Table to be created
const options = {
schema: schema,
location: 'US',
};
const [table] = await bigquery
.dataset(datasetId)
.createTable(tableId, options);
console.log(`Table ${table.id} created.`);
res.send(`Table ${table.id} created.`);
}
}
createTable();
});
how can I resolve this?