Static file handler for Jaguar
Provides two ways to serve static files
1) StaticFileHandler
: RequestHandler based
2) StaticFile
: Interceptor based
StaticFileHandler
is RequestHandler based. It can be directly added to Jaguar server usingaddApi
method or included in an Api using IncludeApi annotation.
Future main() async {
final server = new Jaguar();
server.addApi(
new StaticFileHandler('/public/*', new Directory('./example/static/')));
await server.serve();
}
StaticFile
is an interceptor that substituted JaguarFile in response with actual content of the file
JaguarFile (JaguarFile) points to.
@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();
}