question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wildcard Method Requests

See original GitHub issue

Description

The current method implementations don’t support catch-all endpoints.

Requested Syntax

const server = require('server');
const { status } = server.reply;
const { get } = server.router;

server(
  // This should get invoked for every request
  // An alternative syntax would be to support Regular Expressions.
  get('*', (ctx) => {
    return status(200);
  })
);

Current Workaround

const server = require('server');
const { status } = server.reply;

server(
  (ctx) => {
    if (ctx.method !== 'GET') return;

    // Do super cool api stuff
    return status(200);
  })
);

Relevant Code

The following code doesn’t support wildcards / catch-all endpoints.

https://github.com/franciscop/server/blob/dd1ad51bcd1cd80f64ff119e75edb51d3b6acbd9/router/generic.js#L21-L23

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
teologovcommented, Nov 23, 2017

Hi guys. Yes, I should probably consider to remove the asterisk and migrate the module to version 2.x of path-to-regexp.

1reaction
franciscopcommented, Nov 26, 2017

I upgraded server to 1.0.7, please @nick-woodward let me know if this fixes the issue for you. I fixed the path-to-regexp version and hardcoded path-to-regexp-wrap. So it should install the right version and work as expected with both yarn and npm.

For version 2.0 of server I don’t know if we will depend on express or not; if we do, it’ll be very likely 5.0. I close this as I am really not sure what will happen by then and it’s still quite far away.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - When to use generic methods and when to use wild-card?
If you want to enforce some relationship on the different types of method arguments, you can't do that with wildcards, you have to...
Read more >
URL Query Parameter Wildcard
Purpose: Identifies requests by whether a query string parameter in the requested URL matches a pattern defined by a wildcardThis type of value...
Read more >
Access-Control-Allow-Methods - HTTP - MDN Web Docs
A comma-delimited list of the allowed HTTP request methods. * (wildcard). The value " * " only counts as a special wildcard value...
Read more >
Searching with a wildcard character - BMC Documentation
Searching with a wildcard character. Users can use the percent sign (%) wildcard for any type of search to broaden the set of...
Read more >
Wildcard Query Parameter Support - TechDocs - Broadcom Inc.
This section provides a couple of basic examples for using the wildcard (*) search. Retrieving a List of Switches. The following sample request...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found