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

Stream error on loading swagger doc page #38

Closed
taist24 opened this issue Sep 7, 2022 · 1 comment
Closed

Stream error on loading swagger doc page #38

taist24 opened this issue Sep 7, 2022 · 1 comment

Comments

@taist24
Copy link

taist24 commented Sep 7, 2022

Package version

1.4.1

Node.js and npm version

Node: v16.16.0 & npm: 8.16.0

Sample Code (to reproduce the issue)

I'd version v1.4.0 installed earlier and it was working fine until today when I upgraded it to the latest i.e. v1.4.1. On loading the swagger doc page I'm getting this error.

Endpoint: http://localhost:3333/docs/index.html

{"fd":null,"path":"/Users/istiyaktailor/Documents/Projects/credilio-api/node_modules/swagger-ui-dist/index.html","flags":"r","mode":438,"end":null,"bytesRead":0,"closed":false,"_readableState":{"objectMode":false,"highWaterMark":65536,"buffer":{"head":null,"tail":null,"length":0},"length":0,"pipes":[],"flowing":null,"ended":false,"endEmitted":false,"reading":false,"constructed":false,"sync":true,"needReadable":false,"emittedReadable":false,"readableListening":false,"resumeScheduled":false,"errorEmitted":false,"emitClose":true,"autoDestroy":true,"destroyed":false,"errored":null,"closed":false,"closeEmitted":false,"defaultEncoding":"utf8","awaitDrainWriters":null,"multiAwaitDrain":false,"readingMore":false,"dataEmitted":false,"decoder":null,"encoding":null,"object_mode":false,"high_water_mark":65536,"end_emitted":false,"need_readable":false,"emitted_readable":false,"readable_listening":false,"resume_scheduled":false,"error_emitted":false,"emit_close":true,"auto_destroy":true,"close_emitted":false,"default_encoding":"utf8","await_drain_writers":null,"multi_await_drain":false,"reading_more":false,"data_emitted":false},"_events":{},"_eventsCount":1,"bytes_read":0,"readable_state":{"objectMode":false,"highWaterMark":65536,"buffer":{"head":null,"tail":null,"length":0},"length":0,"pipes":[],"flowing":null,"ended":false,"endEmitted":false,"reading":false,"constructed":false,"sync":true,"needReadable":false,"emittedReadable":false,"readableListening":false,"resumeScheduled":false,"errorEmitted":false,"emitClose":true,"autoDestroy":true,"destroyed":false,"errored":null,"closed":false,"closeEmitted":false,"defaultEncoding":"utf8","awaitDrainWriters":null,"multiAwaitDrain":false,"readingMore":false,"dataEmitted":false,"decoder":null,"encoding":null,"object_mode":false,"high_water_mark":65536,"end_emitted":false,"need_readable":false,"emitted_readable":false,"readable_listening":false,"resume_scheduled":false,"error_emitted":false,"emit_close":true,"auto_destroy":true,"close_emitted":false,"default_encoding":"utf8","await_drain_writers":null,"multi_await_drain":false,"reading_more":false,"data_emitted":false},"events":{},"events_count":1}

I debugged the code and noticed that in v1.4.1 we are sending the html file i.e. index.html as stream.

return response.header('Content-Type', contentType).stream(fs.createReadStream(path))

While, in v1.4.0 we read the html file and then send it in response.

let data = await fsp.readFile(path, 'utf-8')
if (fileName.includes('index.html')) {
//replace default host from index.html
data = data.replace(
'https://petstore.swagger.io/v2/swagger.json',
this.config.get('swagger.specUrl')
)
}
return response.header('Content-Type', contentType).send(data)

I could confirm that reading the file first using fs.readFileSync and then sending it in response via response.send(file) fixes the issue.

@VladyslavParashchenko
Copy link
Collaborator

Sorry for the late response.
I tested it on Node 14, 16, 18. Package works. Maybe it was Adonis's issue with file streaming.

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

No branches or pull requests

2 participants