-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: uses netlify functions and firestore for lib templates
- Loading branch information
1 parent
08870d5
commit 2f4d4b7
Showing
11 changed files
with
17,209 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/js/firebase/firebase-config.json | ||
/seed | ||
Dockerfile | ||
.dockerignore | ||
# Local Netlify folder | ||
.netlify | ||
*.env* | ||
*node_modules |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "netlify dev", | ||
"type": "node", | ||
"request": "launch", | ||
"skipFiles": ["<node_internals>/**"], | ||
"outFiles": ["${workspaceFolder}/.netlify/functions-serve/**/*.js"], | ||
"program": "${workspaceFolder}/node_modules/.bin/netlify", | ||
"args": ["dev"], | ||
"console": "integratedTerminal", | ||
"env": { "BROWSER": "none" }, | ||
"serverReadyAction": { | ||
"pattern": "Server now ready on (https?://[\\w:.-]+)", | ||
"uriFormat": "%s", | ||
"action": "debugWithChrome" | ||
} | ||
}, | ||
{ | ||
"name": "netlify functions:serve", | ||
"type": "node", | ||
"request": "launch", | ||
"skipFiles": ["<node_internals>/**"], | ||
"outFiles": ["${workspaceFolder}/.netlify/functions-serve/**/*.js"], | ||
"program": "${workspaceFolder}/node_modules/.bin/netlify", | ||
"args": ["functions:serve"], | ||
"console": "integratedTerminal" | ||
} | ||
] | ||
} | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[functions] | ||
node_bundler = "esbuild" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Import the functions you need from the SDKs you need | ||
import { initializeApp } from "firebase/app"; | ||
// TODO: Add SDKs for Firebase products that you want to use | ||
// https://firebase.google.com/docs/web/setup#available-libraries | ||
import { getFirestore, collection, getDocs, getCountFromServer, query, where, limit } from 'firebase/firestore' | ||
|
||
// Your web app's Firebase configuration | ||
// For Firebase JS SDK v7.20.0 and later, measurementId is optional | ||
|
||
const firebaseConfig = { | ||
apiKey: process.env.API_KEY, | ||
authDomain: process.env.AUTH_DOMAIN, | ||
projectId: process.env.PROJECT_ID, | ||
storageBucket: process.env.STORAGE_BUCKET, | ||
messagingSenderId: process.env.MESSAGING_SENDER_ID, | ||
appId: process.env.APP_ID, | ||
measurementId: process.env.MEASUREMENT_ID, | ||
} | ||
|
||
// Initialize Firebase | ||
const app = initializeApp(firebaseConfig); | ||
const db = getFirestore(app); | ||
|
||
export { | ||
db, | ||
collection, | ||
getDocs, | ||
getCountFromServer, | ||
query, | ||
where, | ||
limit, | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { db, collection, getDocs, getCountFromServer, query, where, limit } from "./firebase/init.mjs" | ||
|
||
export default async function getTemplate(request) { | ||
const data = await request.json() | ||
const templatesRef = collection(db, "templates") | ||
const q = query(templatesRef, where("id", "==", data.id), limit(1)) | ||
const querySnapshot = await getDocs(q) | ||
const template = querySnapshot.docs.map(doc => doc.data())[0] | ||
|
||
return new Response(JSON.stringify(template)) | ||
} | ||
|
||
export const config = { | ||
// path: "/api/getTemplate" //! Can't use this until Netilfy fixes their CLI | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { db, collection, getCountFromServer } from "./firebase/init.mjs" | ||
|
||
export default async function getTemplateCount() { | ||
const templatesRef = collection(db, "templates") | ||
const snapshot = await getCountFromServer(templatesRef) | ||
const count = snapshot.data().count | ||
|
||
return new Response(count) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { db, collection } from "./firebase/init.mjs" | ||
export default async function getTemplates() { | ||
const templatesRef = collection(db, 'templates'); | ||
const templateSnapShot = await getDocs(templatesRef); | ||
const templateList = templateSnapShot.docs.map(doc => doc.data()) | ||
return new Response(JSON.stringify(templateList)); | ||
} |
Oops, something went wrong.