Skip to content

Commit dc194a6

Browse files
authored
docs: use a custom directory for serving static files (#334)
1 parent 88e8e3c commit dc194a6

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

docs/docs/basics/serving-static-files.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ sidebar_position: 6
44

55
# Serving Static Files 📁
66

7-
Dart Frog supports serving static files including images, text, json, html, and more. To serve static files, place the files within the `public` directory at the root of the project.
7+
Dart Frog supports serving static files including images, text, json, html, and more.
8+
9+
## Overview 🚀
10+
11+
To serve static files, place the files within the `public` directory at the root of the project.
812

913
For example, if you create a file in `public/hello.txt` which contains the following:
1014

@@ -33,3 +37,25 @@ In production, only files that are in the `/public` directory at build time will
3337
:::caution
3438
Be sure not to have a static file with the same name as a file in the `/routes` directory as this will result in a conflict.
3539
:::
40+
41+
## Using a Custom Directory ✨
42+
43+
Even though Dart Frog uses the `public` directory for serving static files by default, you can also specify a custom directory by creating a [custom entrypoint](/docs/advanced/custom_entrypoint).
44+
45+
Create a `main.dart` at the root of your project with the following contents:
46+
47+
```dart
48+
import 'dart:io';
49+
50+
import 'package:dart_frog/dart_frog.dart';
51+
52+
Future<HttpServer> run(Handler handler, InternetAddress ip, int port) {
53+
const customStaticFilePath = 'api/static';
54+
final cascade = Cascade()
55+
.add(createStaticFileHandler(path: customStaticFilePath))
56+
.add(handler);
57+
return serve(cascade.handler, ip, port);
58+
}
59+
```
60+
61+
In the above example, we're using `api/static` as our static file directory but you can specify a path to any directory for Dart Frog to use.

0 commit comments

Comments
 (0)