Skip to content

Jaguar-dart/jaguar_static_file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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