项目作者: Jaguar-dart

项目描述 :
Static file handler for Jaguar
高级语言: Dart
项目地址: git://github.com/Jaguar-dart/jaguar_static_file.git
创建时间: 2016-12-16T19:00:30Z
项目社区:https://github.com/Jaguar-dart/jaguar_static_file

开源协议:BSD 3-Clause "New" or "Revised" License

下载


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

  1. Future main() async {
  2. final server = new Jaguar();
  3. server.addApi(
  4. new StaticFileHandler('/public/*', new Directory('./example/static/')));
  5. await server.serve();
  6. }

StaticFile

StaticFile is an interceptor that substituted JaguarFile in response with actual content of the file
JaguarFile (JaguarFile) points to.

Usage

  1. @Api()
  2. class MyApi extends _$MyApi {
  3. @Get(path: '/file')
  4. @WrapOne(#staticFile)
  5. JaguarFile getFile(Context ctx) =>
  6. new JaguarFile(Directory.current.path + "/static/file.css");
  7. @Get(path: '/static/:filename*')
  8. @WrapOne(#staticFile)
  9. JaguarFile getDir(Context ctx) => new JaguarFile(
  10. Directory.current.path + '/static/' + ctx.pathParams['filename']);
  11. StaticFile staticFile(Context ctx) => new StaticFile();
  12. }