jaguar_static_file

Provides two ways to serve static files

  1. StaticFileHandler : RequestHandler based
  2. StaticFile : Interceptor based

StaticFileHandler

StaticFileHandler is RequestHandler based. It can be directly added to Jaguar server using addApi method or included in an Api using IncludeApi annotation.

Usage

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 in response with actual content of the file JaguarFile (JaguarFile) points to.

Usage

@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();
}

Libraries

jaguar.static_file
Provides two ways to serve static files [...]