How to access local api on the deployed firebase application? - firebase

I have created a simple todo app for learning purposes. It is a full stack website that consists of a static html file with js script that is accessing api on the same host. Backend is build on node.js with express framework and mongodb. Everything works fine on a local server, that I start with cmd:
firebase serve --only functions,hosting
However when I deploy the app to the firebase cloud with cmd:
firebase deploy
I cannot access JSON file that should be served under /api/todos. Instead I receive 503 error:
The app/api/todos also does not work and gives error: Cannot GET /app/api/todos
I can access the file locally:
How can I access my JSON file after the deployment? How the route /app/api/todos would be translated in the app that is deployed?

You should rewrite your /api route from hosting to functions in firebase.json file
Take a look to this link

Related

why does my firebase deployment does not run my website

my cli interface approval of my website deployment
when i run my website i get this
i deployed to the firebase server and expected the server to run my coded website but does not deploy
I have run the website but all i get is i should another from firebase hosting
Firebase Hosting Setup Complete
You're seeing this because you've successfully setup Firebase Hosting. Now it's time to go build something extraordinary! this is the message i get on my website instead of my html css and javascript code

Deploy Blazor to Firebase and have error Firebase Hosting Setup Complete

I want to deploy my Blazor project with Firebase hosting. I have tried a few times to deploy but have the same erorr Firebase Hosting Setup Complete. Deploy Blazor project
firebase login
firebase init
What do you want to use as your public directory? public
Configure as a single-page app (rewrite all urls to /index.html)? No
Set up automatic builds and deploys with GitHub? No
File public/index.html already exists. Overwrite? No
Skipping write of public/index.html
firebase deploy
First of all, you can deploy to firebase hosting only client side app. So your app must be Blazor WebAssembly single-page app. Moreover you are not overwriting index.html so you will see the default firebase file (you can check this). So you have to overwrite default index.html with yours.

nextjs on vercel / zeit writing to disk fs.writeFile

I am using a custom server with nextjs to inject some serverSideProps / getInitialProps into files. What I am doing is having something on the server update a json file every minute or so and then the getServerSideProps/getInitialProps functions read the json file from disk to populate data quickly (without having to do a network request for data).
Everything works great in localhost and when doing a build/running the build locally. In production / after deploying to vercel i get the error: Internal Server Error when trying to open a page. Vercel offers build logs but not any logs for the running custom server.
Is this likely a problem to do with unable to write to disk in the vm's that vercel uses to deploy apps?
Is there an example out there of how I can read/write to disk with a custom server in nextjs for this purpose?
Vercel is a serverless platform and doesn't support a custom server.
If possible, you can migrate away from the custom server (with API routes) or consider other hosting options.
Next.js Deployment

Firebase hosting public folder alias

I have express, react based existing project that I managed to port to Firebase hosting with cloud functions successfully..at least on the dev server.
It looks like this..
This is running on http://localhost:5000/ with command
firebase serve --only functions,hosting
Now, when I deploy this, it looks like
This is NOT a static site. Following the firebase vid here
https://www.youtube.com/watch?v=LOeioOKUKI8
So I have express server running with
app.use('/static',express.static('../public'));
I had to do this because otherwise, firebase hosting treats each path as public path and it messes up scripts sourcing from public folder and also my react router in react app.
While this works on local server run by firebae, it throws 404 on prod.
Failed to load resource: the server responded with a status of 404 ()
The point is I got all this working on local machine but the deployment just won't oblige.
The deployment was not smooth.
firebase deploy
didn't work.
firebase --only hosting
worked.
firebase --only functions
did not work for quite sometime.
It kept throwing
Error setting up the execution environment for your function. Please try again after a few minutes.
a few times before it finally worked. And I didn't change anything to make it work. Just did it by itself.
Is there something I am missing? I am very new to firebase hosting.
I already have a production site running somewhere and I wish to port it to firebase. But I can not have random 'try again after a few minutes problems'.
But first things first, why are my static files not rendering on prod when they do on dev?
Thanks
Your public directory will need to be nested beneath your functions folder, as only files within the functions folder are deployed to Cloud Functions and available from Node.js.
The local emulator is not actively guarding against this kind of tree navigation, which is why it works locally.
In general, though, you'll likely want to restructure your app a bit so that your static assets are deployed to Firebase Hosting directly rather than being served by Express.

Is "firebase serve" just a plan vanilla dev server?

Is firebase serve, the development server for Firebase, just a plain vanilla web server that serves files over HTTP, or does it do something special for Firebase apps?
More specifically, is there any reason to use firebase serve in development if it's more convenient in my situation to use another development web server (e.g., webpack-dev-server or a local Apache or IIS)?
The firebase serve command in the Firebase CLI interprets the instructions in your firebase.json file and serves the web site based on those.
If you're using another local dev server, you'll have to make sure it follows the same rules. That's typically not hard, but it somewhat of a hassle to ensure the firebase.json and configuration of the dev server stay in sync.

Resources