Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Allow configuration of the Cloud Function generated for full-stack web frameworks (#5504)
- Improve error message during deploy when given invalid hosting rewrite rule (#5533)
- Generate ESM-compatible SSR function for web frameworks (#5540)
31 changes: 22 additions & 9 deletions src/frameworks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,15 +572,28 @@ ${firebaseDefaults ? `__FIREBASE_DEFAULTS__=${JSON.stringify(firebaseDefaults)}\
if (bootstrapScript) await writeFile(join(functionsDist, "bootstrap.js"), bootstrapScript);

// TODO move to templates
await writeFile(
join(functionsDist, "server.js"),
`const { onRequest } = require('firebase-functions/v2/https');
const server = import('firebase-frameworks');
exports.${functionId} = onRequest(${JSON.stringify(
frameworksBackend || {}
)}, (req, res) => server.then(it => it.handle(req, res)));
`
);

if (packageJson.type === "module") {
await writeFile(
join(functionsDist, "server.js"),
`import { onRequest } from 'firebase-functions/v2/https';
const server = import('firebase-frameworks');
export const ${functionId} = onRequest(${JSON.stringify(
frameworksBackend || {}
)}, (req, res) => server.then(it => it.handle(req, res)));
`
);
} else {
await writeFile(
join(functionsDist, "server.js"),
`const { onRequest } = require('firebase-functions/v2/https');
const server = import('firebase-frameworks');
exports.${functionId} = onRequest(${JSON.stringify(
frameworksBackend || {}
)}, (req, res) => server.then(it => it.handle(req, res)));
`
);
}
} else {
// No function, treat as an SPA
// TODO(jamesdaniels) be smarter about this, leave it to the framework?
Expand Down