Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.
Releases
@astrojs/[email protected]
Major Changes
#159
adb8bf2a4caeead9a1a255740c7abe8666a6f852
Thanks @alexanderniebuhr! - Updates and prepares the adapter to be more flexibile, stable and composable for the future. Includes several breaking changes.Upgrade Guide
We are commited to provide a smooth upgrade path for our users. This guide will describe what has changed from v9.x to v10 to help you to migrate your existing projects to the latest version of the adapter. For complete documentation of all v10 configuration settings and usage, please see the current, updated Cloudflare adapter documentation.
We will provide at least 4 weeks of limited maintanance support for the previous version 9 of the adapter. Please plan to upgrade your project within this time frame, using the instructions below.
Adapter's
mode
option & Cloudflare FunctionsThe
mode
option has been removed from the adapter. The adapter now defaults to the previousadvanced
mode and this is the only official supported option moving forward.If you are already using
mode: 'advanced'
in yourastro.config.mjs
file, you can safely remove it.import cloudflare from '@astrojs/cloudflare'; import { defineConfig } from 'astro/config'; export default defineConfig({ adapter: cloudflare({ - mode: 'advanced', }), });
If you are using
mode: 'directory'
, and don't have any custom Cloudflare functions in the/function
folder, you should be able to remove themode
option, without any issues.import cloudflare from '@astrojs/cloudflare'; import { defineConfig } from 'astro/config'; export default defineConfig({ adapter: cloudflare({ - mode: 'directory', }), });
If you are using
mode: 'directory'
, and you have custom Cloudflare functions in the/function
folder, you will need to manually migrate them to Astro Server Endpoints (API Routes). If you need to access Cloudflare Bindings, you can usectx.locals
. For further reference, please check the Adapters Documentation on Cloudflare Runtime Usage.Adapter's
functionPerRoute
optionThe
functionPerRoute
option has been removed from the adapter. The adapter now defaults to the previousfalse
value. If you are usingfunctionPerRoute: true
in yourastro.config.mjs
file, you can safely remove it. This change will not break any existing projects, but you will no longer be generating a single function for each route.import cloudflare from '@astrojs/cloudflare'; import { defineConfig } from 'astro/config'; export default defineConfig({ adapter: cloudflare({ - functionPerRoute: true, }), });
Local Runtime
The adapter replaces the
runtime
options with a new set ofplatformProxy
options to enable local runtime support when usingastro dev
.If you are already using a
wrangler.toml
file, you can safely replace your existingruntime
options with the appropriateplatformProxy
options.If you define your bindings in the
astro.config.mjs
file, you need to first migrate your project to use awrangler.toml
configuration file for defining your bindings. You can find more information on how to do this in the Cloudflare docs about wrangler. Then, replaceruntime
options with the new correspondingplatformProxy
options as above.If you have typed
locals
in your./src/env.d.ts
file, you need to runwrangler types
in your project and update the file.Routes
The
routes.strategy
option has been removed as you will no longer have the option to choose a strategy in v10 of this adpater.If you are using
routes.strategy
, you can remove it. You might observe a differentdist/_routes.json
file, but it should not affect your project's behavior.Additionally the
routes.include
&routes.exclude
options have changed their name and type. If you were previously using them, move these to the newroutes.extend
property and update their types:process.env
In the old version of the adapter we used to expose all the environment variables to
process.env
. This is no longer the case, as it was unsafe. If you need to use environment variables, you need to use eitherAstro.locals.runtime.env
orcontext.locals.runtime.env
. There is no way to access the environment variables directly fromprocess.env
or in the global scope.If you need to access the environment variables in global scope, you should refactor your code to pass the environment variables as arguments to your function or file.
If you rely on any third library that uses
process.env
, please open an issue and we can investigate what the best way to handle this is.Node.js APIs compatibility
The adapter still supports the same Node.js APIs as Cloudflare does, but you need to adapt your vite configuration and enable the Cloudflare
nodejs_compat
flag.