Giter Club home page Giter Club logo

firebase-ssr-starter's Introduction

firebase-ssr-starter

Firebase + Next.js + AMP = ๐Ÿฑโ€๐Ÿ‘“; In other words, built for MAXIMUM SEO and MAXIMUM FLEXIBILITY with no compromises (or ragerts)

Environments

There are three type of environments required for this app to run.

  1. Firebase Functions
  2. Client-side
  3. Service Worker

Firebase Functions environments

These environments come in two flavors, environment.js and environment.test.js.

Here are samples for both:

/functions/environments/environment.js

module.exports = {
  algolia: {
    applicationId: 'TO2F04TXTS',
    adminApiKey: '123456789',
    prefix: 'firebaseSSRStarter',
  },
  firebase: {
    apiKey: 'AIzaSyBRLf1WkEBxAw5owXqTTlFIIjYNR1hoatg',
    authDomain: 'fir-ssr-starter.firebaseapp.com',
    databaseURL: 'https://fir-ssr-starter.firebaseio.com',
    projectId: 'fir-ssr-starter',
    storageBucket: '',
    messagingSenderId: '58348257612',
  },
  schema: {
    customClaims: 'custom-claims',
    messages: 'permission-based/user-owned/messages',
    messageLogs: 'admin/logs/messages',
    messageStats: 'admin/stats/messages',
    notifications: 'notifications',
    pushNotifications: 'push-notifications',
    settings: 'permission-based/user-owned/settings',
    users: 'users',
  },
  notifications: {
    ADMIN: 'admin',
    MESSAGE: 'message',
  },
  pubSub: {
    PROCESS_NOTIFICATIONS: 'process-notifications',
  },
};

/functions/environments/environment.test.js

const prodEnvironment = require('./environment');

module.exports = {
  ...prodEnvironment,
  isTest: true,
  schema: {
    customClaims: 'test-custom-claims',
    messages: 'permission-based/user-owned/test-messages',
    messageLogs: 'admin/logs/test-messages',
    messageStats: 'admin/stats/test-messages',
    notifications: 'test-notifications',
    pushNotifications: 'test-push-notifications',
    settings: 'permission-based/user-owned/test-settings',
    users: 'test-users',
  },
};

Client-side environments

Client-side environments come in two flavors, environment.js and environment.dev.js.

Sample /environments/environment.js

import schema from './schema';
export default {
  algolia: {
    applicationId: 'TO2F04TXTS',
    searchOnlyApiKey: 'e37dcec3965d1cabde303b17e65d25f0',
    prefix: 'firebaseSSRStarter',
  },
  firebase: {
    apiKey: 'AIzaSyBRLf1WkEBxAw5owXqTTlFIIjYNR1hoatg',
    authDomain: 'fir-ssr-starter.firebaseapp.com',
    databaseURL: 'https://fir-ssr-starter.firebaseio.com',
    projectId: 'fir-ssr-starter',
    storageBucket: 'fir-ssr-starter.appspot.com',
    messagingSenderId: '58348257612',
  },
  notifications: {
    ADMIN: 'admin',
    MESSAGE: 'message',
  },
  schema,
};

Sample /environments/environment.dev.js

import prodEnvironment from './environment';
export default {
  ...prodEnvironment,
  isDev: true,
};

Service Worker environment

And finally, we have our Service Worker that needs its own environment.

This one is a bit different because it's adding environment to global scope:

Sample /environments/environment.sw.js

environment = {
  firebase: {
    apiKey: 'AIzaSyBRLf1WkEBxAw5owXqTTlFIIjYNR1hoatg',
    authDomain: 'fir-ssr-starter.firebaseapp.com',
    databaseURL: 'https://fir-ssr-starter.firebaseio.com',
    projectId: 'fir-ssr-starter',
    storageBucket: '',
    messagingSenderId: '58348257612',
  },
};

Deploying

Get a Firebase CI token

Run yarn global add firebase-tools if you don't have firebase-tools on your machine.

Run firebase login:ci and follow the prompts to generate a Firebase CI token. Use firebase login:ci --no-localhost if you're having trouble.

Copy ./env.list.dist to env.list and replace FIREBASE_TOKEN=XXXXX with FIREBASE_TOKEN=YOUR-TOKEN-HERE.

Install Docker

Install Docker using the Docker Community Edition(CE) Install Guide.

Build Docker image to deploy

For Bash run ./bin/build.sh.

For Powershell run .\bin\build.ps1.

OPTIONAL: Run the deploy image interactively

For Bash run ./bin/interactive.sh.

For Powershell run .\bin\interactive.ps1.

Deploy the built code

For Bash run ./bin/deploy.sh.

For Powershell run .\bin\deploy.ps1.

Use Google Pub/Sub to trigger push notifications

Process a single user's notifications with the following pub-sub command:

gcloud pubsub topics publish process-user-notifications --message '{"uid": "123456"}'

Process all user notifications with the following pub-sub command:

gcloud pubsub topics publish process-notifications --message '{}'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.