Skip to content

Instantly share code, notes, and snippets.

@jthegedus
Last active May 25, 2020 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jthegedus/64cd5e233b8870349580930bff5e327a to your computer and use it in GitHub Desktop.
Save jthegedus/64cd5e233b8870349580930bff5e327a to your computer and use it in GitHub Desktop.
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,
// the absolute directory from the package.json file that initialises this module
// IE: the absolute path from the root of the Cloud Function
conf: config,
});
const handle = app.getRequestHandler();
const server = functions.https.onRequest((request, response) => {
// log the page.js file or resource being requested
console.log("File: " + request.originalUrl);
return app.prepare().then(() => handle(request, response));
});
exports.nextjs = { server };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment