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

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

Closed
tjoskar opened this issue Sep 21, 2022 · 1 comment · Fixed by #306
Closed

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

tjoskar opened this issue Sep 21, 2022 · 1 comment · Fixed by #306

Comments

@tjoskar
Copy link

tjoskar commented Sep 21, 2022

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?

@ivan-tymoshenko
Copy link
Collaborator

ivan-tymoshenko commented Sep 21, 2022

/: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.

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 a pull request may close this issue.

2 participants