Skip to content

Commit 83b86f0

Browse files
Merge branch 'dimbslmh-migration-fastify-cors'
2 parents a278b12 + ff82cba commit 83b86f0

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

content/migration.md

+21
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,27 @@ bootstrap();
9090

9191
> info **Hint** There have been no changes to path matching in Fastify v5 (except for middleware, see the section below), so you can continue using the wildcard syntax as you did before. The behavior remains the same, and routes defined with wildcards (like `*`) will still work as expected.
9292
93+
#### Fastify CORS
94+
95+
By default, only [CORS-safelisted methods](https://fetch.spec.whatwg.org/#methods) are allowed. If you need to enable additional methods (such as `PUT`, `PATCH`, or `DELETE`), you must explicitly define them in the `methods` option.
96+
97+
```typescript
98+
const methods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE']; // OR comma-delimited string 'GET,POST,PUT,PATH,DELETE'
99+
100+
const app = await NestFactory.create<NestFastifyApplication>(
101+
AppModule,
102+
new FastifyAdapter(),
103+
{ cors: { methods } },
104+
);
105+
106+
// OR alternatively, you can use the `enableCors` method
107+
const app = await NestFactory.create<NestFastifyApplication>(
108+
AppModule,
109+
new FastifyAdapter(),
110+
);
111+
app.enableCors({ methods });
112+
```
113+
93114
#### Fastify middleware registration
94115

95116
NestJS 11 now uses the latest version of the [path-to-regexp](https://www.npmjs.com/package/path-to-regexp) package to match **middleware paths** in `@nestjs/platform-fastify`. As a result, the `(.*)` syntax for matching all paths is no longer supported. Instead, you should use named wildcards.

0 commit comments

Comments
 (0)