Skip to content

Add separate Router ability and print routes

Latest
Compare
Choose a tag to compare
@deriegle deriegle released this 23 Aug 14:48

Added the ability to create separate routers

api_router.dart

Router apiRouter() {
  final router = Router();

  router.get('/', (req, res) {
    res.json({ 'hello': 'world' });
  });
}

view_router.dart

Router viewRouter() {
  final router = Router();

  router.get('/', (req, res) {
    res.render('index');
  });

  return router;
}

main.dart

import 'api_router.dart';
import 'view_router.dart';

void main() {
  final app = express();

  app.useRouter('/', viewRouter());
  app.useRouter('/api', apiRouter());

  app.listen(3000);
}

Added the ability to print routes

All routes will show after listen is called.

final app = express();

app.set('print routes', true);

app.get('/', (req, res) => res.json({ 'hello': true }));

app.listen(3000);
[GET] /
Listening on port 3000