Open-next Cloudflare / Docker / Setup (#248)
* Add Cloudflare generator with Wrangler and OpenNext support This update introduces a new Cloudflare generator to streamline configuration and deployment via Wrangler and OpenNext. It registers the necessary templates, modifies project files, and adds Cloudflare-specific scripts and dependencies to the package.json. Additionally, .hbs files are updated in .prettierignore for formatting consistency. * Add GitHub username prompt and improve setup scripts Introduce a prompt for GitHub username to personalize project setup. Enhance the setup scripts by adding PNPM verification, configuring `upstream` remote, and removing the `origin` remote. Adjust health check and error handling for better reliability. * Add Dockerfile generator to turbo generators Introduced a new generator to create Dockerfile configurations for standalone Next.js applications. This includes modifying `next.config.mjs` for standalone output, updating dependencies in `package.json`, and adding a Dockerfile template. The generator is now registered in the turbo setup. * Add console-based logger implementation. This is required for edge environments such as Cloudflare. * Remove deprecated Supabase client utilities The `server-actions-client`, `route-handler-client`, and `server-component-client` utilities have been removed in favor of `getSupabaseServerClient`. This simplifies and consolidates the API, ensuring consistency across server-side usage. Version bumped to 2.9.0 to reflect breaking changes.
This commit is contained in:
committed by
GitHub
parent
76bfeddd32
commit
4cfb4f936f
0
turbo/generators/templates/cloudflare/dev.vars.hbs
Normal file
0
turbo/generators/templates/cloudflare/dev.vars.hbs
Normal file
90
turbo/generators/templates/cloudflare/generator.ts
Normal file
90
turbo/generators/templates/cloudflare/generator.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import type { PlopTypes } from '@turbo/gen';
|
||||
import { execSync } from 'node:child_process';
|
||||
|
||||
import packageJson from '../../../../package.json';
|
||||
|
||||
export function createCloudflareGenerator(plop: PlopTypes.NodePlopAPI) {
|
||||
plop.setGenerator('cloudflare', {
|
||||
description: 'Cloudflare generator',
|
||||
actions: [
|
||||
{
|
||||
type: 'add',
|
||||
templateFile: 'templates/cloudflare/wrangler.jsonc.hbs',
|
||||
path: 'apps/web/wrangler.jsonc',
|
||||
data: {
|
||||
name: packageJson.name,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'add',
|
||||
templateFile: 'templates/cloudflare/open-next.config.ts.hbs',
|
||||
path: 'apps/web/open-next.config.ts',
|
||||
},
|
||||
{
|
||||
type: 'add',
|
||||
templateFile: 'templates/cloudflare/dev.vars.hbs',
|
||||
path: 'apps/web/.dev.vars',
|
||||
},
|
||||
{
|
||||
type: 'modify',
|
||||
path: 'apps/web/next.config.mjs',
|
||||
async transform(content) {
|
||||
content += `
|
||||
import { initOpenNextCloudflareForDev } from '@opennextjs/cloudflare';
|
||||
|
||||
void initOpenNextCloudflareForDev();
|
||||
`;
|
||||
|
||||
return content;
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'modify',
|
||||
path: 'apps/web/package.json',
|
||||
async transform(content) {
|
||||
const pkg = JSON.parse(content);
|
||||
|
||||
const deps = ['wrangler', '@opennextjs/cloudflare'];
|
||||
|
||||
const getVersion = async (dep: string) => {
|
||||
const res = await fetch(
|
||||
`https://registry.npmjs.org/-/package/${dep}/dist-tags`,
|
||||
);
|
||||
|
||||
const json = await res.json();
|
||||
return json.latest;
|
||||
};
|
||||
|
||||
for (const dep of deps) {
|
||||
const version = await getVersion(dep);
|
||||
pkg.devDependencies![dep] = `^${version}`;
|
||||
}
|
||||
|
||||
pkg.scripts['preview'] =
|
||||
'opennextjs-cloudflare build && opennextjs-cloudflare preview';
|
||||
pkg.scripts['deploy'] =
|
||||
'opennextjs-cloudflare build && opennextjs-cloudflare deploy';
|
||||
pkg.scripts['cf-typegen'] =
|
||||
'wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts';
|
||||
|
||||
return JSON.stringify(pkg, null, 2);
|
||||
},
|
||||
},
|
||||
async () => {
|
||||
/**
|
||||
* Install deps and format everything
|
||||
*/
|
||||
execSync('pnpm i', {
|
||||
stdio: 'inherit',
|
||||
});
|
||||
|
||||
execSync(
|
||||
`pnpm run format:fix`,
|
||||
);
|
||||
|
||||
return 'Package scaffolded';
|
||||
},
|
||||
],
|
||||
prompts: [],
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import { defineCloudflareConfig } from "@opennextjs/cloudflare";
|
||||
|
||||
export default defineCloudflareConfig();
|
||||
54
turbo/generators/templates/cloudflare/wrangler.jsonc.hbs
Normal file
54
turbo/generators/templates/cloudflare/wrangler.jsonc.hbs
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* For more details on how to configure Wrangler, refer to:
|
||||
* https://developers.cloudflare.com/workers/wrangler/configuration/
|
||||
*/
|
||||
{
|
||||
"$schema": "node_modules/wrangler/config-schema.json",
|
||||
"name": "{{name}}",
|
||||
"main": ".open-next/worker.js",
|
||||
"keep_vars": true,
|
||||
"compatibility_date": "2025-04-02",
|
||||
"compatibility_flags": [
|
||||
"nodejs_compat"
|
||||
],
|
||||
// Minification helps to keep the Worker bundle size down and improve start up time.
|
||||
"minify": true,
|
||||
"assets": {
|
||||
"binding": "ASSETS",
|
||||
"directory": ".open-next/assets"
|
||||
},
|
||||
"observability": {
|
||||
"enabled": true
|
||||
},
|
||||
/**
|
||||
* Smart Placement
|
||||
* Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
|
||||
*/
|
||||
"placement": { "mode": "smart" },
|
||||
|
||||
/**
|
||||
* Bindings
|
||||
* Bindings allow your Worker to interact with resources on the Cloudflare Developer Platform, including
|
||||
* databases, object storage, AI inference, real-time communication and more.
|
||||
* https://developers.cloudflare.com/workers/runtime-apis/bindings/
|
||||
*/
|
||||
|
||||
/**
|
||||
* Environment Variables
|
||||
* https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
|
||||
*/
|
||||
"vars": {},
|
||||
/**
|
||||
* Note: Use secrets to store sensitive data.
|
||||
* https://developers.cloudflare.com/workers/configuration/secrets/
|
||||
*/
|
||||
|
||||
/**
|
||||
* Service Bindings (communicate between multiple Workers)
|
||||
* https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
|
||||
*/
|
||||
// "services": [{ "binding": "MY_SERVICE", "service": "my-service" }]
|
||||
"d1_databases": [],
|
||||
"kv_namespaces": [],
|
||||
"r2_buckets": []
|
||||
}
|
||||
Reference in New Issue
Block a user