-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
Comments
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: |
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. |
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.
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.
Prerequisites
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
The text was updated successfully, but these errors were encountered: