Wednesday, 9 September 2020

Hosting react node app on firebase using function and hosting

So basically I have my application set up right now with all the information I have been able to get on firebase hosting. When i run the firebase function in localhost everything works fine but when I deploy it or run using firebase serve --only hosting, I get a white page with a react js tab header. I have seen the tutorial posted on youtube by firebase using rendering engines and tried to imitate it but no avail.Here are my codesconst functions = require('firebase-functions'); const express = require('express'); const bodyParser = require('body-parser'); const cors = require('cors'); const helmet = require('helmet'); const app = express(); const path = require('path'); const rateLimit = require("express-rate-limit"); const xss = require("xss-clean") const mongoSanitize = require('express-mongo-sanitize') // app.set('trust proxy', 1); // app.disable('x-powered-by') app.use(express.static(path.join(__dirname, '../build'))) app.get('/*', (req, res) => { res.sendFile(path.join(__dirname, '../build/index.html')) }) /** * SECURITY MIDDLEWARE */ // app.use(helmet()) const limit = rateLimit({ max: 100, // max requests windowMs: 60 * 60 * 1000, // 1 Hour message: 'Too many requests' // message to send }); //middleware app.use(bodyParser.json({ limit: '40kb' })); app.use(bodyParser.urlencoded({ extended: false })) app.use(cors()); app.use(limit) app.use(xss()) app.use(mongoSanitize()); /**LOADERS */ require('./loaders/router')(app) exports.app = functions.https.onRequest(app) This is my firebase.json{ "hosting": { "public": "public", "ignore": [ "firebase.json", "**/.*", "**/node_modules/**" ], "rewrites": [{ "source": "**", "function": "app" }] }, "functions": { "predeploy": [ "npm --prefix \"$RESOURCE_DIR\" run lint" ] } } For my project structure, my function lies inside my creat app folder

Submitted September 09, 2020 at 05:02PM by udbasil

No comments:

Post a Comment