All Projects → jthegedus → Firebase Functions Next Example

jthegedus / Firebase Functions Next Example

Licence: other
Host a Next.js SSR React app on Cloud Functions for Firebase with Firebase Hosting

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Firebase Functions Next Example

Next Routes
Universal dynamic routes for Next.js
Stars: ✭ 2,354 (+994.88%)
Mutual labels:  nextjs, universal, server-rendering, ssr
Next.js
The React Framework
Stars: ✭ 78,384 (+36357.67%)
Mutual labels:  nextjs, universal, server-rendering
Nuxt Ssr Firebase
Nuxt.js Universal App with SSR via Firebase Functions and Firebase Hosting
Stars: ✭ 273 (+26.98%)
Mutual labels:  firebase-functions, firebase, ssr
Angular9 Example App
Angular 13 Example App + Angular CLI + i18n + GraphQL
Stars: ✭ 1,769 (+722.79%)
Mutual labels:  firebase, universal, ssr
Firebase Gcp Examples
🔥 Firebase app architectures, languages, tools & some GCP things! React w Next.js, Svelte w Sapper, Cloud Functions, Cloud Run.
Stars: ✭ 470 (+118.6%)
Mutual labels:  firebase-functions, firebase, nextjs
Laravel Nuxt
A Laravel-Nuxt starter kit.
Stars: ✭ 943 (+338.6%)
Mutual labels:  universal, server-rendering, ssr
React Firebase Starter
Boilerplate (seed) project for creating web apps with React.js, GraphQL.js and Relay
Stars: ✭ 4,366 (+1930.7%)
Mutual labels:  firebase-functions, firebase, ssr
Nuxt.js
The Intuitive Vue(2) Framework
Stars: ✭ 38,986 (+18033.02%)
Mutual labels:  universal, server-rendering, ssr
Startup Landing
Collection of free top of the line startup landing templates built using react/nextjs/gatsby. Free to download, simply edit and deploy! Updated weekly!
Stars: ✭ 176 (-18.14%)
Mutual labels:  nextjs, universal, server-rendering
Virapro.ru
[E-commerce] Plumbing Store
Stars: ✭ 45 (-79.07%)
Mutual labels:  firebase-functions, firebase, ssr
Next Firebase Ssr
An Next.js example repo for building authenticated pages with Firebase Authentication, cookies, and getServerSideProps
Stars: ✭ 192 (-10.7%)
Mutual labels:  firebase, nextjs, ssr
Combinefirebase
Combine wrapper on Google's iOS Firebase library.
Stars: ✭ 126 (-41.4%)
Mutual labels:  firebase-functions, firebase
Next Advanced Apollo Starter
Advanced, but minimalistic Next.js pre-configured starter with focus on DX
Stars: ✭ 131 (-39.07%)
Mutual labels:  nextjs, universal
Nextjs Vercel Firebase
Next.js app using API routes to connect with Firestore.
Stars: ✭ 133 (-38.14%)
Mutual labels:  firebase, nextjs
Next Firebase Auth
Simple Firebase authentication for all Next.js rendering strategies
Stars: ✭ 135 (-37.21%)
Mutual labels:  firebase, nextjs
Gank
🦅 Gank api base △ next.js (react&ssr)
Stars: ✭ 122 (-43.26%)
Mutual labels:  nextjs, ssr
Egg React Ssr
最小而美的Egg + React + SSR 服务端渲染应用骨架,同时支持JS和TS
Stars: ✭ 1,837 (+754.42%)
Mutual labels:  nextjs, ssr
Next Blog
基于react(ssr)服务端框架next.js和antd-design搭建的个人博客
Stars: ✭ 214 (-0.47%)
Mutual labels:  nextjs, ssr
Uvue
Vue CLI plugin to create universal Vue applications with ease
Stars: ✭ 119 (-44.65%)
Mutual labels:  universal, ssr
Reactql
Universal React+GraphQL starter kit: React 16, Apollo 2, MobX, Emotion, Webpack 4, GraphQL Code Generator, React Router 4, PostCSS, SSR
Stars: ✭ 1,833 (+752.56%)
Mutual labels:  universal, ssr

🚨 deprecated, new example at firebase-gcp-examples


Next.js SSR app on Cloud Functions for Firebase with Firebase Hosting

Host a Next.js SSR React app on Cloud Functions for Firebase with Firebase Hosting.

Here is the accompanying Medium PostA new post is being written to describe the new project structure, Firebase partial deployments, Firebase support of pre/post-deploy hooks and what problems these new features solve.

styled with Prettier

Why?

Host your SSR Next.js app on Cloud Functions enabling a low-cost, auto-scaling SSR app experience leveraging Firebase's sweet developer experience.

How?

Firebase Hosting can rewrite routes to a Cloud Function that serves our Server-side Rendered Next.js app. Using a rewrite rule that catches ALL routes we can then host our SSR app on our Firebase Hosting URL instead of the Firebase Cloud Function URL.

instead of:

https://us-central1-<project-name>.cloudfunctions.net/<function-name>

we can use:

<project-name>.firebaseapp.com/

Next.js can then be used to achieve SSR React with Hot-Module Reloading, server and client-side routing, route level code-splitting, route prefetching and more!

A number of issues with Hosting SSR on Firebase were overcome with this method. Please refer to the Medium Post before creating issues here.

Important!

  • This example uses firebase-tools as a devDependency which is run from the node_modules/.bin/ folder via yarn. Yarn will run scripts from either the package.json or binary scripts from node_modules/.bin/. npm run does not check the .bin folder for executables, so if you use npm you will either have to change the scripts to explicitly run the firebase binary from node_modules/.bin/ or install firebase-tools globally and remove it from the devDeps list. Have a look at the Next.js repo's example for how I recommend using npm.

  • Ensure you're running Node 6.11.5 as the functions emulator requires this. I recommend asdf as a version manager and have add an asdf .tool-versions file to define the Node runtime.

  • If using _app.js you may receive the following error on your deployed Cloud Function:

    { Error: Cannot find module '@babel/runtime/regenerator'...
    

    Despite next.js having @babel/runtime as a dependency, you must install it as a dependency directly in this project.

Installation

git clone https://github.com/jthegedus/firebase-functions-next-example
cd firebase-functions-next-example
yarn install

Login to Firebase CLI

This is used as a dev-dependency instead of a global install. I've found this to be a much nicer dev experience.

yarn fblogin

Next.js Development

Standard Next.js development with Hot-module Reloading etc

yarn dev

Local Testing

yarn serve

This finally works now! Note: you must have a valid Firebase project id defined in the .firebaserc file as the serve command does check that the project exists. I believe this is to do with ensuring the relative routes align with your deployed application as the <project id> is used in your URLs.

For those who want to dig deeper into what's actually happening here run this command:

yarn serve --debug

Deploy to Firebase

You will need to connect the project to your Firebase project. Edit the name in .firebaserc or run firebase init and choose not to override any files.

Deploy Hosting resources and the rewrite Cloud Function

yarn deploy-app

Deploy functions not used for the SSR

Deploy all functions specified in the function group. Edit this script to add more function groups. - see Partial deploys docs for how to use function groups.

yarn deploy-funcs

Deploy everything to Firebase

yarn deploy-all

Clean dist Folder

yarn clean

A note on Code Compatibility

Everything was tested on Ubuntu 17.04 with Bash. This should work on Bash on Ubuntu on Windows without any changes. If you wish for Windows native support please submit an issue so we can work on Windows compatibility. Please report any macOS errors as I do not have access to a device to test. My development environment can be found here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].