delvedor/find-my-way

TypeError: currentNode.createStaticChild is not a function for wildcard route

Closed this issue · 1 comments

Hi,

Let's say I have the following code:

const http = require("http");
const router = require("find-my-way")();

router.on("GET", "*.js", (req, res, params) => {
  res.end(`{"route":"${req.url}"}`);
});

const server = http.createServer((req, res) => {
  router.lookup(req, res);
});

server.listen(3000, (err) => {
  if (err) throw err;
  console.log("Server listening on: http://localhost:3000");
});

With find-my-way@4.5.1 (that is included in fastify@3.29.2) the code above works fine and I can run curl http://localhost:3000/assets/hello.js and get back {"route":"/assets/hello.js"} but with find-my-way@7.2.0 (that is included in fastify@4.6.0) I get:

TypeError: currentNode.createStaticChild is not a function
    at Router._on (node_modules/find-my-way/index.js:190:33)
    at Router.on (node_modules/find-my-way/index.js:136:10)
    at Object.<anonymous> (server.cjs:20:8)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47

I guess this is a bug? Or is it a better way to get all requests that request for a javascript file?

/:file(.*).js is the correct way to define regexp params in the path. Any param can be placed between slashes. I'm afraid there is no longer support for this feature. If you know how deep can be your path, you can try this: /:folder/:file(.*).js.