Deploy Vercel Hazel on Firebase and access it like: mySoftwareWebsite.com/get
Path "/get" can be replaced with your desired path
Related: https://github.com/vercel/hazel
Deploy Vercel Hazel on Firebase and access it like: mySoftwareWebsite.com/get
Path "/get" can be replaced with your desired path
Related: https://github.com/vercel/hazel
| const functions = require("firebase-functions"); | |
| const hazel = require("hazel-server"); // Run "npm i hazel-server" in your functions/ directory first | |
| const express = require("express"); | |
| const cors = require("cors"); | |
| const app = express(); | |
| // Middlewares | |
| app.use(cors()); | |
| app.use((req, res, next) => { | |
| // Remove trailing slash | |
| if (req.url.slice(-1) === "/") { | |
| req.url = req.url.slice(0, -1); | |
| } | |
| // Redirect "/get" to "/" since Hazel needs root url ie. "/" | |
| req.url = req.url.replace("/get", "/").replace("//", "/"); | |
| // Forward request to the handler | |
| next("route"); | |
| }); | |
| // Internal routes are handled by Hazel | |
| app.get("*", (req, res) => { | |
| hazel({ | |
| //Git repo where releases are published | |
| account: YOUR_GITHUB_USERNAME, | |
| repository: YOUR_GITHUB_REPO_NAME, | |
| })(req, res); | |
| }); | |
| module.exports.fetchElectronReleases = () => { | |
| return functions.https.onRequest(app); | |
| }; |
| // ++ Existing content | |
| "hosting":[ | |
| { | |
| "target": "YOUR_FIREBASE_SITE", | |
| "public": "YOUR_PUBLIC_DIR", | |
| "rewrites": [ | |
| { | |
| "source": "/get/**", | |
| "function": "fetchElectronReleases" //This will execute given firebase function on this hosting route | |
| }, | |
| { | |
| "source": "/get", | |
| "function": "fetchElectronReleases" | |
| }, | |
| { | |
| "source": "**", | |
| "destination": "/index.html" | |
| } | |
| ] | |
| } | |
| ] |