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

#794 - Scope app middleware to a list of paths #837

Merged
merged 1 commit into from
Nov 19, 2014

Conversation

bajtos
Copy link
Member

@bajtos bajtos commented Nov 19, 2014

Add a new argument to app.middleware allowing developers
to restrict the middleware to a list of paths or regular expresions.

Modify app.middlewareFromConfig to pass config.paths as the second
arg of app.middleware.

Examples:

// A string path (interpreted via path-to-regexp)
app.middleware('auth', '/admin', ldapAuth);

// A regular expression
app.middleware('initial', /^\/~(admin|root)/, rejectWith404);

// A list of scopes
app.middleware('routes', ['/api', /^\/assets/.*\.json$/], foo);

// From config
app.middlewareFromConfig(
  handlerFactory,
  {
    phase: 'initial',
    paths: ['/scope', /^\/(a|b)/]
  });

Close #794

/to @raymondfeng @ritch please review

@bajtos bajtos added the #review label Nov 19, 2014
@bajtos bajtos added this to the #Epic: Components milestone Nov 19, 2014
@bajtos bajtos force-pushed the feature/scope-middleware-to-path branch from c040c28 to dbf4d12 Compare November 19, 2014 11:11
@bajtos bajtos changed the title Scope app middleware to a list of paths #794 - Scope app middleware to a list of paths Nov 19, 2014
Add a new argument to `app.middleware` allowing developers
to restrict the middleware to a list of paths or regular expresions.

Modify `app.middlewareFromConfig` to pass `config.paths` as the second
arg of `app.middleware`.

Examples:

    // A string path (interpreted via path-to-regexp)
    app.middleware('auth', '/admin', ldapAuth);

    // A regular expression
    app.middleware('initial', /^\/~(admin|root)/, rejectWith404);

    // A list of scopes
    app.middleware('routes', ['/api', /^\/assets/.*\.json$/], foo);

    // From config
    app.middlewareFromConfig(
      handlerFactory,
      {
        phase: 'initial',
        paths: ['/scope', /^\/(a|b)/]
      });
@bajtos bajtos force-pushed the feature/scope-middleware-to-path branch from dbf4d12 to 2baa4b0 Compare November 19, 2014 14:43
@raymondfeng
Copy link
Member

👍

bajtos added a commit that referenced this pull request Nov 19, 2014
@bajtos bajtos merged commit 1c1e64c into master Nov 19, 2014
@bajtos bajtos deleted the feature/scope-middleware-to-path branch November 19, 2014 18:21
@bajtos bajtos removed the #review label Nov 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scope middleware to a subpath
3 participants