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

Bug: The root path is spliced repeatedly. #437

Open
2 tasks done
byteslaves opened this issue Aug 23, 2024 · 3 comments · May be fixed by #440
Open
2 tasks done

Bug: The root path is spliced repeatedly. #437

byteslaves opened this issue Aug 23, 2024 · 3 comments · May be fixed by #440
Labels
bug Confirmed bug good first issue Good for newcomers

Comments

@byteslaves
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.28.1

Plugin version

9.1.0

Node.js version

20

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

win11

Description

Upon employing this plugin, utilizing art-template as the template engine, and assigning a path to the root property, an error ensues due to the unintended concatenation of two paths during the rendering process.
This behavior is not observed when using the EJS template engine.

The relevant code snippet is provided below:

fastify.register(fastifyView, {
engine: {
'art-template': require('art-template')
},
root:'./views/rat/'
})

fastify.get("/art", (req, reply) => {
reply.view('./index.art', { text: "text" });
});

error message:
err: {
"type": "Error",
"message": "template not found: ENOENT: no such file or directory, open 'S:\user\js-ts-project\fastify\hello-world\views\rat\views\rat\index.art'",
"stack":
TemplateError: template not found: ENOENT: no such file or directory, open 'S:\user\js-ts-project\fastify\hello-world\views\rat\views\rat\index.art'
"name": "TemplateError"
}

Big thanks to all the Fastify contributors!

Link to code that reproduces the bug

No response

Expected Behavior

Can access the directory correctly

@byteslaves
Copy link
Author

I've pinpointed the code causing the issue and modified it within the module I'm using. Now, the art-template template engine is working as expected. I'm not entirely sure if there are any unintended side effects from this change, as I haven't delved too deeply into the module's overall mechanics. The modified line, number 415, is:
        // confs.filename = join(templatesDir, filename)
        confs.filename = filename

@byteslaves byteslaves changed the title The root path is spliced repeatedly. Bug: The root path is spliced repeatedly. Aug 24, 2024
@mcollina
Copy link
Member

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@mcollina mcollina added bug Confirmed bug good first issue Good for newcomers labels Aug 25, 2024
@byteslaves
Copy link
Author

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

I apologize, but as I'm just starting to learn how to use Fastify, I may not be able to submit a pull request to resolve this issue right now.

richdouglasevans added a commit to richdouglasevans/point-of-view that referenced this issue Oct 20, 2024
Closes fastify#437

When the `root` option is passed explicitly and the `art-template` engine is in use, the `root` value is being duplicated in the resolved template directory.

This leads to an error like this: notice how `templates` is present twice in the path.

```
  -{"statusCode":500,"error":"Internal Server Error","message":"template not found: ENOENT: no such file or directory, open
  '/home/rich/point-of-view/templates/templates/index.art'"}
```

The fix is to remove this duplication. The `resolveTemplateDir` function already uses any `root` option (if present) so there's no need to consider it again.
@richdouglasevans richdouglasevans linked a pull request Oct 20, 2024 that will close this issue
4 tasks
richdouglasevans added a commit to richdouglasevans/point-of-view that referenced this issue Oct 25, 2024
Closes fastify#437

When the `root` option is passed explicitly and the `art-template` engine is in use, the `root` value is being duplicated in the resolved template directory.

This leads to an error like this: notice how `templates` is present twice in the path.

```
  -{"statusCode":500,"error":"Internal Server Error","message":"template not found: ENOENT: no such file or directory, open
  '/home/rich/point-of-view/templates/templates/index.art'"}
```

The fix is to remove this duplication. The `resolveTemplateDir` function already uses any `root` option (if present) so there's no need to consider it again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants