Reputation: 123
Currently i'm learning express and Firebase. I can deploy an angular or react page (front-end) to Firebase.
And now, i'm trying to create the back-end using express, then i realize, i cant just simply deploying it as another project to Firebase since Firebase hosting will looking for index.html as entry point (*please correct me if i'm wrong). I've tried Firebase functions but still can't.
Can i set a javascript (expressjs) file to Firebase as entry point?
thanks.
Upvotes: 5
Views: 5737
Reputation: 317497
You can deploy an Express app to Cloud Functions for Firebase as an HTTP trigger. There is a sample that illustrates this. The basic form of implementation looks like this in your Cloud Functions index.js:
const functions = require('firebase-functions')
const express = require('express')
const app = express()
// configure app here, add routes, whatever
exports.api = functions.https.onRequest(app)
Now you can access your routes under the path https://your-assigned-hostname/api/whatever
EDIT
You also need to configure your firebase.json file if you want to redirect every request to the Express app.
Add this line inside the hosting object: "rewrites" : [{"source" : "**", "function" : "api"}]
Upvotes: 9