This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require("firebase-functions") | |
const cors = require("cors") | |
exports.iowa = functions.region("us-central1").https.onRequest((req, res) => { | |
return cors()(req, res, () => { | |
res.send("Hi from Iowa, USA") | |
}) | |
}) | |
exports.london = functions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const router = require("express").Router() | |
router.get("/list", (req, res) => { | |
res.send(`this is /list on userRoute`) | |
}) | |
router.get("/", (req, res) => { | |
res.send(`this is / on userRoute`) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"hosting": { | |
"public": "public", | |
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"], | |
"rewrites": [ | |
{ | |
"source": "/api/**", | |
"function": "api" | |
}, | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"hosting": { | |
"public": "public", | |
"ignore": [ | |
"firebase.json", | |
"**/.*", | |
"**/node_modules/**" | |
], | |
"rewrites": [{ | |
"source": "/api/**", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let API_ROOT = "" | |
if (location.hostname == "127.0.0.1" || location.hostname == "localhost") { | |
API_ROOT = `https://localhost:5001/${firebaseConfig.projectId}/us-central1` | |
}else{ | |
API_ROOT = `https://us-central1-${firebaseConfig.projectId}.cloudfunctions.net` | |
} | |
fetch(API_ROOT+"/api/sentences", { | |
method: "GET" | |
}).then((response) => console.log(response.json())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const router = require("express").Router() | |
router.get("/api/user/data", (req, res) => { | |
res.send(`this is /api/user/data`) | |
}) | |
router.get("/api/data", (req, res) => { | |
res.send(`this is /api/data`) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require("firebase-functions") | |
const express = require("express") | |
const app = express() | |
// my routings | |
const apiRoute = require("./api") | |
// add routes to the express app. | |
app.use("/api", apiRoute) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let functions = firebase.functions() | |
functions.useFunctionsEmulator('http://localhost:5001') | |
let btn = document.querySelector("#btn-get-data") | |
let label = document.querySelector("#label") | |
let retrieveData = functions.httpsCallable("retrieve") | |
btn.addEventListener("click", (e) => { | |
retrieveData() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<title>Welcome to Firebase Hosting</title> | |
<!-- update the version number as needed --> | |
<script defer src="/__/firebase/7.19.1/firebase-app.js"></script> | |
<!-- include only the Firebase features as you need --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require("firebase-functions") | |
exports.retrieve = functions.https.onCall((req, res) => { | |
// Response.send("This is Data") | |
return "This is data" | |
}) |