https://github.com/jaguar-dart/jaguar_static_file
Static file handler for Jaguar
https://github.com/jaguar-dart/jaguar_static_file
dart interceptor request-handler server server-side static-file-server static-files
Last synced: 7 months ago
JSON representation
Static file handler for Jaguar
- Host: GitHub
- URL: https://github.com/jaguar-dart/jaguar_static_file
- Owner: Jaguar-dart
- License: other
- Created: 2016-12-16T19:00:30.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-10-15T21:44:17.000Z (almost 9 years ago)
- Last Synced: 2025-03-16T04:27:56.997Z (over 1 year ago)
- Topics: dart, interceptor, request-handler, server, server-side, static-file-server, static-files
- Language: Dart
- Homepage: https://pub.dartlang.org/packages/jaguar_static_file
- Size: 17.6 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jaguar_static_file
Provides two ways to serve static files
1) [`StaticFileHandler`](StaticFileHandler) : RequestHandler based
2) [`StaticFile`](StaticFile) : Interceptor based
# StaticFileHandler
`StaticFileHandler` is [RequestHandler](RequestHandler) based. It can be directly added to [Jaguar](Jaguar) server using
[`addApi`](addApi) method or included in an [Api](Api) using [IncludeApi](IncludeApi) annotation.
## Usage
```dart
Future main() async {
final server = new Jaguar();
server.addApi(
new StaticFileHandler('/public/*', new Directory('./example/static/')));
await server.serve();
}
```
# StaticFile
`StaticFile` is an interceptor that substituted [JaguarFile](JaguarFile) in response with actual content of the file
[JaguarFile] (JaguarFile) points to.
## Usage
```dart
@Api()
class MyApi extends _$MyApi {
@Get(path: '/file')
@WrapOne(#staticFile)
JaguarFile getFile(Context ctx) =>
new JaguarFile(Directory.current.path + "/static/file.css");
@Get(path: '/static/:filename*')
@WrapOne(#staticFile)
JaguarFile getDir(Context ctx) => new JaguarFile(
Directory.current.path + '/static/' + ctx.pathParams['filename']);
StaticFile staticFile(Context ctx) => new StaticFile();
}
```
[JaguarFile]: https://www.dartdocs.org/documentation/jaguar/latest/jaguar/JaguarFile-class.html
[Jaguar]: https://www.dartdocs.org/documentation/jaguar/latest/jaguar/Jaguar-class.html
[IncludeApi]: https://www.dartdocs.org/documentation/jaguar/latest/jaguar/IncludeApi-class.html
[Api]: https://www.dartdocs.org/documentation/jaguar/latest/jaguar/Api-class.html
[RequestHandler]: https://www.dartdocs.org/documentation/jaguar/latest/jaguar/RequestHandler-class.html
[StaticFileHandler]: https://www.dartdocs.org/documentation/jaguar_static_file/latest/jaguar_static_file/StaticFileHandler-class.html
[StaticFile]: https://www.dartdocs.org/documentation/jaguar_static_file/latest/jaguar_static_file/StaticFile-class.html