Closed chimon2000 closed 3 months ago
:tada: This issue has been resolved in version 1.4.0 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket:
@HomelessDinosaur it seems like middleware works differently depending on the SDK used. When using the Node version, I can add a middleware to enable cors for the entire API like so:
import { HttpMiddleware } from '@nitric/sdk'
export const corsMiddleware: HttpMiddleware = (ctx, next) => {
ctx.res.headers['Access-Control-Allow-Origin'] = ['*']
ctx.res.headers['Access-Control-Allow-Headers'] = [
'Origin, Content-Type, Accept, Authorization',
]
ctx.res.headers['Access-Control-Allow-Methods'] = ['GET,POST,DELETE,OPTIONS']
return next(ctx)
}
If I apply that same version in Dart, the middleware fails to work as expected.
import 'package:nitric_sdk/nitric.dart';
final HttpHandler corsMiddleware = (ctx) {
ctx.res.headers['Access-Control-Allow-Origin'] = ['*'];
ctx.res.headers['Access-Control-Allow-Headers'] = [
'Origin, Content-Type, Accept, Authorization',
];
ctx.res.headers['Access-Control-Allow-Methods'] = ['GET,POST,DELETE,OPTIONS'];
return ctx.next();
};
Feature Request
Suggestion
I would like support for middleware similar to the JavaScript SDK
Value
Two reasons:
Alternatives
Currently, I am defining middleware at the request level, which is tedious.
Other info
n/a