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

URL parameter "format=html" causes an error "options.render is not a function" #307

Closed
2 tasks done
is2ei opened this issue May 21, 2022 · 1 comment · Fixed by #308
Closed
2 tasks done

URL parameter "format=html" causes an error "options.render is not a function" #307

is2ei opened this issue May 21, 2022 · 1 comment · Fixed by #308

Comments

@is2ei
Copy link
Contributor

is2ei commented May 21, 2022

Prerequisites

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

Fastify version

3.29.0

Plugin version

5.0.2

Node.js version

16.14.2

Operating system

Linux

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

20.04.0

Description

The option list.format=html requires list.render.

https://github.com/fastify/fastify-static#listformat

Directory list can be also in html format; in that case, list.render function is required.

The problem is that it is possible to pass list.format=html using the URL parameter even though list.render option is not given.

Steps to Reproduce

  1. Register @fastify/static with list: true.
  2. Access the URL with query parameter ?format=html.
  3. You will see an error.

short example:

const fastify = require('fastify')();
const path = require('path');

fastify.register(require('@fastify/static'), {
  root: path.join(__dirname, 'public'),
  index: false,
  list: true,
});

fastify.listen(3000);

error example:

{"statusCode":500,"error":"Internal Server Error","message":"options.render is not a function"}

I created an example on stackblitz: https://stackblitz.com/edit/node-hdvl2e?file=index.js

Screen Shot 2022-05-21 at 20 29 16

Expected Behavior

I guess we have some options.

  • Allowing list.render with list.format=json.
  • Disabling ?format=html in URL parameter.
  • Documenting not to use ?format=html.
@is2ei is2ei changed the title URL parameter "format=html" is not acceptable option URL parameter "format=html" causes error May 21, 2022
@is2ei is2ei changed the title URL parameter "format=html" causes error URL parameter "format=html" causes an error May 21, 2022
@is2ei is2ei changed the title URL parameter "format=html" causes an error URL parameter "format=html" causes an error "options.render is not a function" May 21, 2022
@mcollina
Copy link
Member

I think the first option is the way to go.

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