Skip to content

Instantly share code, notes, and snippets.

@jthegedus
jthegedus / next-aso-ssg-export.js
Last active April 20, 2022 18:57
Next.js static asset hoisting for Firebase Hosting CDN
var shell = require("shelljs");
var nextjsConfig = require("../next.config");
var distDir = nextjsConfig.distDir || ".next";
var BUILD_ID = shell.cat(`${distDir}/BUILD_ID`);
function hoistPages(fileExt, outputPath) {
console.log(
`${distDir}/server/static/${BUILD_ID}/pages/**/*${fileExt} -> ${outputPath}/`
);
shell.mkdir("-p", outputPath);
@jthegedus
jthegedus / cloud-function-upload-dirs
Created May 25, 2020 03:07
github.com/jthegedus/firebase-gcp-examples/tree/master/functions-nextjs
┌ nextjs/ <-- Next.js distribution directory
| └ ...
├ next.config.js <-- Next.js configuration
├ package-lock.json
├ package.json
└ server.js <-- HTTPS Cloud Function for our Next.js Server
@jthegedus
jthegedus / package.json
Created May 25, 2020 03:05
github.com/jthegedus/firebase-gcp-examples/tree/master/functions-nextjs
{
...
"main": "server.js",
...
"dependencies": {
...
},
"engines": {
"node": "10"
},
@jthegedus
jthegedus / firebase-functions.json
Created May 25, 2020 03:04
github.com/jthegedus/firebase-gcp-examples/tree/master/functions-nextjs
{
...
"functions": {
"source": ".",
"ignore": [
"firebase.json",
"firbease-debug.log",
"**/.*",
"**/node_modules/**",
"components/**",
@jthegedus
jthegedus / firebase-hosting.json
Created May 25, 2020 03:03
github.com/jthegedus/firebase-gcp-examples/tree/master/functions-nextjs
{
...
"hosting": [{
"site": "TODO_YOUR_WEB_APP_DEPLOY_TARGET_HERE",
"public": "out",
"cleanUrls": true,
"rewrites": [{
"source": "**",
"function": "nextjs-server"
}]
@jthegedus
jthegedus / example-app-file-structure
Created May 25, 2020 03:02
github.com/jthegedus/firebase-gcp-examples/tree/master/functions-nextjs
┌ components/ <-- React Components
| └ ...
├ helpers/
| └ utils.js <-- Firestore data to JSON helper
├ nextjs/ <-- Next.js distribution directory
| └ ... configured in next.config.js
├ out/ <-- public/ + hoisted nextjs/ static content
| └ ...
├ pages/ <-- Next.js Pages
| └ ...
@jthegedus
jthegedus / sitemap
Created May 25, 2020 03:01
github.com/jthegedus/firebase-gcp-examples/tree/master/functions-nextjs
┌ ○ / <-- static
├ ○ /404 <-- static
├ ● /about <-- SSG page
├ λ /blog <-- SSR page
├ ● /blog/[pid] <-- SSG dynamic route with fallback:true
└ ○ /blog/not-a-post <-- static
+ First Load JS shared by all
├ static/pages/_app.js
├ chunks/commons.some_uid.js
├ chunks/framework.some_uid.js
@jthegedus
jthegedus / server.js
Last active May 25, 2020 03:09
Next.js on Cloud Functions for Firebase
const admin = require("firebase-admin");
const functions = require("firebase-functions");
const next = require("next");
const config = require("./next.config");
admin.initializeApp();
const dev = process.env.NODE_ENV !== "production";
const app = next({
dev,
@jthegedus
jthegedus / function.js
Created May 26, 2019 06:50
Cloud Run web server and dependencies example
exports.helloWorld = (req, res) => {
res.send('Hello, World');
};
@jthegedus
jthegedus / graphql-functions.js
Last active March 16, 2021 09:48
GraphQL & Cloud Functions for Firebase example
import {https} from 'firebase-functions';
import gqlServer from './graphql/server';
const server = gqlServer();
// Graphql api
// https://us-central1-<project-name>.cloudfunctions.net/api/
const api = https.onRequest(server);
export {api};