Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle a multi-host driver with the framework #110

Closed
thosakwe opened this issue Jun 12, 2019 · 3 comments
Labels

Comments

@thosakwe
Copy link
Member

@thosakwe thosakwe commented Jun 12, 2019

Starting discussion point in thread: https://gitter.im/angel_dart/discussion?at=5cfffa44a30be21ff9f1cc77

A well-written utility class can potentially be included that makes it easier to serve multiple hostnames within the same Dart process.

Tentative example. The API design is not yet so good.

var multiHost = AngelMultiHost({
  'example.com': await Angel().configure(example.configureServer),
   RegExp(r'*\.yes.com'): await Angel().configure(yes.configureServer),
});

await multiHost.startServer((app) => AngelHttp(app));

The gist, though:

  • Maps Patterns to Angel objects, and dispatches corresponding requests to the right server.
  • Connects to some Driver implementation.

Ideas:

  • Cleaner constructor:
var multiHost = AngelMultiHost.configure({
  'example.com': example.configureServer,
   RegExp(r'*\.yes.com'): yes.configureServer,
});
@thosakwe

This comment has been minimized.

Copy link
Member Author

@thosakwe thosakwe commented Jun 12, 2019

What may be a better solution would be to implement this as a middleware:

var multiHost = HostnameRouter.configure({
  'api.example.com': api.configureServer,
  'example.com': example.configureServer,
});

app.fallback(multiHost.handleRequest);
app.fallback((req, res) => throw AngelHttpException.notFound());

This way, no patches to Driver are necessary.

@thosakwe

This comment has been minimized.

Copy link
Member Author

@thosakwe thosakwe commented Jun 12, 2019

Strings can be parsed into RegExp a very simple grammar:

  • *. becomes the regex ([^$]*\.)?
  • Multiple domains for the same app can be separated by a |:
    • example.com|www.example.com -> (example.com)|(www.example.com)
@thosakwe

This comment has been minimized.

Copy link
Member Author

@thosakwe thosakwe commented Jul 17, 2019

Just pending some unit tests.

@thosakwe thosakwe closed this Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.