How to serve both dynamic and static pages with Dart and shelf?

后端 未结 3 1020
感情败类
感情败类 2021-02-06 03:36

Using shelf_static to serve static web pages through Dart is no problem:

var staticHandler = createStatic         


        
3条回答
  •  深忆病人
    2021-02-06 03:54

    You can use Cascade. It creates a chain of handlers, moving to the next one if the previous one gives a 404 or 405 response.

    var staticHandler = createStaticHandler(staticPath, defaultDocument:'home.html');
    var routes = new Router()
        ..get('/item/{itemid}', handleItem);
    
    var handler = new Cascade()
        .add(staticHandler)
        .add(routes.hander)
        .handler;
    io.serve(handler, 'localhost', port).then((server) {
      print('Serving at http://${server.address.host}:${server.port}');
    });
    

提交回复
热议问题