From ef53ad14e1fe1cf87585df64fc71fb25c4e77454 Mon Sep 17 00:00:00 2001 From: teetangh Date: Mon, 17 Apr 2023 23:13:21 +0530 Subject: [PATCH 1/3] added firebase files --- .github/workflows/firebase-hosting-merge.yml | 20 +++++ .../firebase-hosting-pull-request.yml | 17 ++++ database.rules.json | 7 ++ firestore.indexes.json | 4 + firestore.rules | 8 ++ functions/.eslintrc.js | 28 ++++++ functions/.gitignore | 1 + functions/index.js | 9 ++ functions/package.json | 26 ++++++ public/404.html | 33 +++++++ public/index.html | 89 +++++++++++++++++++ 11 files changed, 242 insertions(+) create mode 100644 .github/workflows/firebase-hosting-merge.yml create mode 100644 .github/workflows/firebase-hosting-pull-request.yml create mode 100644 database.rules.json create mode 100644 firestore.indexes.json create mode 100644 firestore.rules create mode 100644 functions/.eslintrc.js create mode 100644 functions/.gitignore create mode 100644 functions/index.js create mode 100644 functions/package.json create mode 100644 public/404.html create mode 100644 public/index.html diff --git a/.github/workflows/firebase-hosting-merge.yml b/.github/workflows/firebase-hosting-merge.yml new file mode 100644 index 0000000..490bcdf --- /dev/null +++ b/.github/workflows/firebase-hosting-merge.yml @@ -0,0 +1,20 @@ +# This file was auto-generated by the Firebase CLI +# https://github.com/firebase/firebase-tools + +name: Deploy to Firebase Hosting on merge +'on': + push: + branches: + - main +jobs: + build_and_deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: npm ci && npm run build + - uses: FirebaseExtended/action-hosting-deploy@v0 + with: + repoToken: '${{ secrets.GITHUB_TOKEN }}' + firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_NOTEUPS_WEB_ORIGINAL_BACKEND }}' + channelId: live + projectId: noteups-web-original-backend diff --git a/.github/workflows/firebase-hosting-pull-request.yml b/.github/workflows/firebase-hosting-pull-request.yml new file mode 100644 index 0000000..a56b2e9 --- /dev/null +++ b/.github/workflows/firebase-hosting-pull-request.yml @@ -0,0 +1,17 @@ +# This file was auto-generated by the Firebase CLI +# https://github.com/firebase/firebase-tools + +name: Deploy to Firebase Hosting on PR +'on': pull_request +jobs: + build_and_preview: + if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: npm ci && npm run build + - uses: FirebaseExtended/action-hosting-deploy@v0 + with: + repoToken: '${{ secrets.GITHUB_TOKEN }}' + firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_NOTEUPS_WEB_ORIGINAL_BACKEND }}' + projectId: noteups-web-original-backend diff --git a/database.rules.json b/database.rules.json new file mode 100644 index 0000000..f54493d --- /dev/null +++ b/database.rules.json @@ -0,0 +1,7 @@ +{ + /* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */ + "rules": { + ".read": false, + ".write": false + } +} \ No newline at end of file diff --git a/firestore.indexes.json b/firestore.indexes.json new file mode 100644 index 0000000..415027e --- /dev/null +++ b/firestore.indexes.json @@ -0,0 +1,4 @@ +{ + "indexes": [], + "fieldOverrides": [] +} diff --git a/firestore.rules b/firestore.rules new file mode 100644 index 0000000..c38e3ae --- /dev/null +++ b/firestore.rules @@ -0,0 +1,8 @@ +rules_version = '2'; +service cloud.firestore { + match /databases/{database}/documents { + match /{document=**} { + allow read, write: if false; + } + } +} \ No newline at end of file diff --git a/functions/.eslintrc.js b/functions/.eslintrc.js new file mode 100644 index 0000000..f4cb76c --- /dev/null +++ b/functions/.eslintrc.js @@ -0,0 +1,28 @@ +module.exports = { + env: { + es6: true, + node: true, + }, + parserOptions: { + "ecmaVersion": 2018, + }, + extends: [ + "eslint:recommended", + "google", + ], + rules: { + "no-restricted-globals": ["error", "name", "length"], + "prefer-arrow-callback": "error", + "quotes": ["error", "double", {"allowTemplateLiterals": true}], + }, + overrides: [ + { + files: ["**/*.spec.*"], + env: { + mocha: true, + }, + rules: {}, + }, + ], + globals: {}, +}; diff --git a/functions/.gitignore b/functions/.gitignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/functions/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/functions/index.js b/functions/index.js new file mode 100644 index 0000000..0d3ca7f --- /dev/null +++ b/functions/index.js @@ -0,0 +1,9 @@ +const functions = require("firebase-functions"); + +// // Create and deploy your first functions +// // https://firebase.google.com/docs/functions/get-started +// +// exports.helloWorld = functions.https.onRequest((request, response) => { +// functions.logger.info("Hello logs!", {structuredData: true}); +// response.send("Hello from Firebase!"); +// }); diff --git a/functions/package.json b/functions/package.json new file mode 100644 index 0000000..1e606ae --- /dev/null +++ b/functions/package.json @@ -0,0 +1,26 @@ +{ + "name": "functions", + "description": "Cloud Functions for Firebase", + "scripts": { + "lint": "eslint .", + "serve": "firebase emulators:start --only functions", + "shell": "firebase functions:shell", + "start": "npm run shell", + "deploy": "firebase deploy --only functions", + "logs": "firebase functions:log" + }, + "engines": { + "node": "16" + }, + "main": "index.js", + "dependencies": { + "firebase-admin": "^11.5.0", + "firebase-functions": "^4.2.0" + }, + "devDependencies": { + "eslint": "^8.15.0", + "eslint-config-google": "^0.14.0", + "firebase-functions-test": "^3.0.0" + }, + "private": true +} diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000..829eda8 --- /dev/null +++ b/public/404.html @@ -0,0 +1,33 @@ + + + + + + Page Not Found + + + + +
+

404

+

Page Not Found

+

The specified file was not found on this website. Please check the URL for mistakes and try again.

+

Why am I seeing this?

+

This page was generated by the Firebase Command-Line Interface. To modify it, edit the 404.html file in your project's configured public directory.

+
+ + diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..cb94d49 --- /dev/null +++ b/public/index.html @@ -0,0 +1,89 @@ + + + + + + Welcome to Firebase Hosting + + + + + + + + + + + + + + + + + + + +
+

Welcome

+

Firebase Hosting Setup Complete

+

You're seeing this because you've successfully setup Firebase Hosting. Now it's time to go build something extraordinary!

+ Open Hosting Documentation +
+

Firebase SDK Loading…

+ + + + From eeba3375695361c8386902f5c642697c654aad27 Mon Sep 17 00:00:00 2001 From: teetangh Date: Wed, 7 Jun 2023 04:07:46 +0530 Subject: [PATCH 2/3] completed firebase initiation --- .env.sample | 9 +++++++++ .firebaserc | 5 +++++ firebase.config.js | 22 ++++++++++++++++++++++ firebase.json | 41 +++++++++++++++++++++++++++++++++++++++++ functions/index.js | 22 ++++++++++++++++------ functions/package.json | 8 ++++---- public/index.html | 20 ++++++++++---------- storage.rules | 12 ++++++++++++ 8 files changed, 119 insertions(+), 20 deletions(-) create mode 100644 .firebaserc create mode 100644 firebase.config.js create mode 100644 firebase.json create mode 100644 storage.rules diff --git a/.env.sample b/.env.sample index 90b845e..9525097 100644 --- a/.env.sample +++ b/.env.sample @@ -32,3 +32,12 @@ FACEBOOK_CLIENT_SECRET= GITHUB_CLIENT_ID= GITHUB_CLIENT_SECRET= +FIREBASE_API_KEY= +FIREBASE_AUTH_DOMAIN= +FIREBASE_DATABASE_URL= +FIREBASE_PROJECT_ID= +FIREBASE_STORAGE_BUCKET= +FIREBASE_MESSAGING_SENDER_ID= +FIREBASE_APP_ID= +FIREBASE_MEASUREMENT_ID= + diff --git a/.firebaserc b/.firebaserc new file mode 100644 index 0000000..b87b610 --- /dev/null +++ b/.firebaserc @@ -0,0 +1,5 @@ +{ + "projects": { + "default": "noteups-web-original-backend" + } +} diff --git a/firebase.config.js b/firebase.config.js new file mode 100644 index 0000000..b123c2f --- /dev/null +++ b/firebase.config.js @@ -0,0 +1,22 @@ +// Import the functions you need from the SDKs you need +import { initializeApp } from "firebase/app"; +import { getAnalytics } from "firebase/analytics"; +// TODO: Add SDKs for Firebase products that you want to use +// https://firebase.google.com/docs/web/setup#available-libraries + +// Your web app's Firebase configuration +// For Firebase JS SDK v7.20.0 and later, measurementId is optional +const firebaseConfig = { + apiKey: process.env.FIREBASE_API_KEY, + authDomain: process.env.FIREBASE_AUTH_DOMAIN, + databaseURL: process.env.FIREBASE_DATABASE_URL, + projectId: process.env.FIREBASE_PROJECT_ID, + storageBucket: process.env.FIREBASE_STORAGE_BUCKET, + messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID, + appId: process.env.FIREBASE_APP_ID, + measurementId: process.env.FIREBASE_MEASUREMENT_ID, +}; + +// Initialize Firebase +const app = initializeApp(firebaseConfig); +const analytics = getAnalytics(app); diff --git a/firebase.json b/firebase.json new file mode 100644 index 0000000..f066668 --- /dev/null +++ b/firebase.json @@ -0,0 +1,41 @@ +{ + "functions": [ + { + "source": "functions", + "codebase": "default", + "ignore": [ + "node_modules", + ".git", + "firebase-debug.log", + "firebase-debug.*.log" + ], + "predeploy": [ + "npm --prefix \"$RESOURCE_DIR\" run lint" + ] + } + ], + "database": { + "rules": "database.rules.json" + }, + "firestore": { + "rules": "firestore.rules", + "indexes": "firestore.indexes.json" + }, + "hosting": { + "public": "public", + "ignore": [ + "firebase.json", + "**/.*", + "**/node_modules/**" + ], + "rewrites": [ + { + "source": "**", + "destination": "/index.html" + } + ] + }, + "storage": { + "rules": "storage.rules" + } +} diff --git a/functions/index.js b/functions/index.js index 0d3ca7f..e81477f 100644 --- a/functions/index.js +++ b/functions/index.js @@ -1,9 +1,19 @@ -const functions = require("firebase-functions"); +/** + * Import function triggers from their respective submodules: + * + * const {onCall} = require("firebase-functions/v2/https"); + * const {onDocumentWritten} = require("firebase-functions/v2/firestore"); + * + * See a full list of supported triggers at https://firebase.google.com/docs/functions + */ -// // Create and deploy your first functions -// // https://firebase.google.com/docs/functions/get-started -// -// exports.helloWorld = functions.https.onRequest((request, response) => { -// functions.logger.info("Hello logs!", {structuredData: true}); +const {onRequest} = require("firebase-functions/v2/https"); +const logger = require("firebase-functions/logger"); + +// Create and deploy your first functions +// https://firebase.google.com/docs/functions/get-started + +// exports.helloWorld = onRequest((request, response) => { +// logger.info("Hello logs!", {structuredData: true}); // response.send("Hello from Firebase!"); // }); diff --git a/functions/package.json b/functions/package.json index 1e606ae..a88bc5e 100644 --- a/functions/package.json +++ b/functions/package.json @@ -10,17 +10,17 @@ "logs": "firebase functions:log" }, "engines": { - "node": "16" + "node": "18" }, "main": "index.js", "dependencies": { - "firebase-admin": "^11.5.0", - "firebase-functions": "^4.2.0" + "firebase-admin": "^11.8.0", + "firebase-functions": "^4.3.1" }, "devDependencies": { "eslint": "^8.15.0", "eslint-config-google": "^0.14.0", - "firebase-functions-test": "^3.0.0" + "firebase-functions-test": "^3.1.0" }, "private": true } diff --git a/public/index.html b/public/index.html index cb94d49..ad41d9d 100644 --- a/public/index.html +++ b/public/index.html @@ -6,17 +6,17 @@ Welcome to Firebase Hosting - + - - - - - - - - - + + + + + + + + +