0

How can I configure an express.js app that uses Angular as the front end framework and multiple route files and the server and Angular communicating with each other via service level api calls, so that it can be deployed in Firebase via Firebase hosting.

I am having difficulty in getting a correct way of configuring firebase.json file and the overall project to be deployed in Firebase.

As of now when I deploy my app only the index.html page in the dist folder is coming in either via api or in any ways.

const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const cors = require("cors");
const path = require("path");
const http = require("http");
// const functions = require('firebase-functions')
const server = http.createServer(app);


const authRoutes = require("./api/auth");
const dataRoutes = require("./api/data");
const deviceRoutes = require('./api/device');



app.use(cors());
app.options("*", cors());
app.use(bodyParser.json());
app.use(
  bodyParser.urlencoded({
    extended: false
  })
);
app.use(express.static(path.join(__dirname, "dist")));

const port = process.env.PORT || "1337";
app.set("port", port);

app.use("/api/auth", authRoutes);
app.use("/api/data", dataRoutes);
app.use("/api/device", deviceRoutes);

app.get("*", function (req, res) {
  res.sendFile(path.join(__dirname, "dist/index.html"));
});



// exports.app = functions.https.onRequest(app);
server.listen(port, () => console.log(`Server running on localhost:${port}`));

Do I need to use Firebase functions?

Edit

Can we include cloud functions in any ways to help in hosting this app?

2 Answers 2

1

I tried this before and It's not possible to do this.

Sign up to request clarification or add additional context in comments.

8 Comments

But there is a video that shows we can deploy nodejs app in firebase hosting right? Doesn't that count?
There is a video that can excute nodejs yes but to host it is not possible.
Why? I mean that is from the firebase team?
You can only deploy nodejs functions. So if you want to do this maybe you can deploy every api call separately. And then fire it with adding values to firestore.
so what you meant to say is that, we need to deploy each and every api call functions that I make in nodejs individual files and then I can do this?
|
0

I have successfully managed to solve this issue, but not directly.

  • I manage to do the angular front end work in a seperate folder and once the build is final i build a production version
  • copy the contents inside the dist folder inside the public folder of the firebase project
  • manage the routes seperately inside the firebase.json file
  • in the index.js file in cloud functions we will call to index.html just like in a mean stack app

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.