Multiple Shelf Proxy Handlers based on different routes

26 views
Skip to first unread message

Bob Rozelle

unread,
May 27, 2016, 11:55:56 AM5/27/16
to Redstone.dart
I understand how to add a Shelf Proxy Handler, for example: ph = proxyHandler('http://localhost:9000'); app.setShelfHandler(ph);
I don't know how to have different Shelf Proxy Handlers based upon different routes.
Thanks,
Bob

Bob Rozelle

unread,
May 27, 2016, 12:12:16 PM5/27/16
to Redstone.dart
5 minutes later ...  All it takes is posting it on a public forum and you figure it out.


  var staticHandler = createStaticHandler("web",
      defaultDocument: "index.html",
      serveFilesOutsidePath: true);
  var proxy1 = proxyHandler('http://localhost:8000');
  var proxy2= proxyHandler('http://localhost:9000');

  app.setShelfHandler((req) {
    print(req.url.path);
    if (req.url.path.startsWith("p1")) {
      return proxy1(req);
    }
    else if (req.url.path.startsWith("p2")) {
      return proxy2(req);
    }

    return staticHandler(req);
  });

  app.setupConsoleLog(Level.INFO);
  app.start();
Reply all
Reply to author
Forward
0 new messages