The reason is that shelf_route methods such as get must be fully consistent with the path. With static files, you don't need exact matches, as the rest of the path tells you the file path.
To do this, you need to use the add method and set exactMatch: false , as currently methods like get , post , etc. Do not set exactMatch .
Next works
void main(List<String> args) { Logger.root.onRecord.listen(print); var staticHandler = createStaticHandler('../static', defaultDocument:'home.html'); final root = router() ..get('/item/{itemid}', (Request request) => 'handling the item') ..add('/', ['GET'], staticHandler, exactMatch: false); printRoutes(root); io.serve(root.handler, InternetAddress.ANY_IP_V6, 9999); }
FYI I added a higher level structure called mojito , which is a thin layer of glue on many components of the shelf, which makes this a little easier.
This is still curious and poorly documented, but in case you are interested, you can do the following
void main(List<String> args) { Logger.root.onRecord.listen(print); final app = mojito.init(); app.router ..get('/item/{itemid}', (String itemid) => 'handling the item $itemid') ..addStaticAssetHandler('/', fileSystemPath: '../static', defaultDocument:'home.html'); app.start(); }
addStaticAssetHandler calls createStaticHandler backstage, but also supports pub invocation in design mode, which is very convenient for things like polymer
Anders
source share