Skip to content

Commit fd8c803

Browse files
authored
docs: custom server entrypoint (#274)
1 parent 9073ab5 commit fd8c803

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

docs/docs/advanced/_category_.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"label": "Advanced",
3+
"position": 5,
4+
"link": {
5+
"title": "Advanced 🧙",
6+
"type": "generated-index",
7+
"description": "Learn advanced Dart Frog concepts."
8+
}
9+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# Custom Server Entrypoint 🎬
6+
7+
Dart Frog supports creating a custom entrypoint in cases where you need fine-grained control over the server initialization or wish to execute code prior to starting the server.
8+
9+
## Creating a Custom Entrypoint ✨
10+
11+
To create a custom entrypoint, simply create a `main.dart` file at the root of your Dart Frog project. The `main.dart` file must expose a top-level `run` method with the following signature:
12+
13+
```dart
14+
import 'dart:io';
15+
16+
import 'package:dart_frog/dart_frog.dart';
17+
18+
Future<HttpServer> run(Handler handler, InternetAddress ip, int port) {
19+
// 1. Execute any custom code prior to starting the server...
20+
21+
// 2. Use the provided `handler`, `ip`, and `port` to create a custom `HttpServer`.
22+
// Or use the Dart Frog serve method to do that for you.
23+
return serve(handler, ip, port);
24+
}
25+
```
26+
27+
The Dart Frog CLI will detect the custom entrypoint and execute your custom `run` method instead of the default implementation.

0 commit comments

Comments
 (0)