gazelle_cors 0.5.0+1
gazelle_cors: ^0.5.0+1 copied to clipboard
Gazelle CORS Plugin is a Dart package that provides Cross-Origin Resource Sharing (CORS) support for Gazelle applications.
example/gazelle_cors_example.dart
import 'dart:async';
import 'package:gazelle_core/gazelle_core.dart';
import 'package:gazelle_cors/gazelle_cors.dart';
class GazelleCorsExampleHandler extends GazelleRouteHandler<String> {
const GazelleCorsExampleHandler();
@override
FutureOr<GazelleResponse<String>> call(
GazelleContext context,
GazelleRequest request,
GazelleResponse response,
) {
return GazelleResponse(
statusCode: GazelleHttpStatusCode.success.ok_200,
body: "Hello, Gazelle!",
);
}
}
void main() async {
// Setup your server.
final app = GazelleApp(
routes: [
GazelleRoute(
name: "",
get: const GazelleCorsExampleHandler(),
// Add CORS hook from the regsitered plugin.
preRequestHooks: (context) => [
context.getPlugin<GazelleCorsPlugin>().corsHook,
],
),
],
plugins: [
GazelleCorsPlugin(corsHeaders: [
GazelleHttpHeader.accessControlAllowOrigin.addValue("example.com"),
])
],
);
// Start your server.
await app.start();
print("Gazelle listening at ${app.serverAddress}");
}