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

Support static files references #137

Merged
merged 5 commits into from Jan 4, 2019

Conversation

kromol
Copy link
Contributor

@kromol kromol commented Dec 18, 2018

No description provided.

@mcollina
Copy link
Member

Thanks for your contribution!

Linting is failing:

standard: Use JavaScript Standard Style (https://standardjs.com)
standard: Run `standard --fix` to automatically fix some problems.
  /home/travis/build/fastify/fastify-swagger/routes.js:46:65: Extra semicolon.
  /home/travis/build/fastify/fastify-swagger/routes.js:49:31: Extra semicolon.
  /home/travis/build/fastify/fastify-swagger/routes.js:50:15: Extra semicolon.
  /home/travis/build/fastify/fastify-swagger/routes.js:55:41: Extra semicolon.
  /home/travis/build/fastify/fastify-swagger/static.js:54:42: Unexpected trailing comma.

Also, can you add a unit test?

@kromol
Copy link
Contributor Author

kromol commented Dec 18, 2018

Yep, I'll fix it. This is still work in progress. I just opened PR so you can track the progress from the beginning :)

@kromol
Copy link
Contributor Author

kromol commented Dec 20, 2018

@mcollina are you OK with using fastify@next for now and updating it to released version later?
Currently there are issues with router which are fixed in fastify 2.

@cemremengu
Copy link
Contributor

@kromol I was waiting for this PR to land actually but if it is really necessary I will bump the version

@mcollina
Copy link
Member

Currently there are issues with router which are fixed in fastify 2.

Which issue?
You can target https://github.com/fastify/fastify-swagger/tree/fastify-next, which is the update to the new version of fastify.

@kromol
Copy link
Contributor Author

kromol commented Dec 20, 2018

I meant this issue - fastify/fastify#1338

Currently the problem is that plugin will have to serve static files from two different locations:

  1. Internal static directory with UI stuff
  2. Directory with yaml/json documentation files <-- this should be dynamic

With current setup I initially was thinking about adding additional regex route to handle only yaml and json files and do not break other static stuff handled by fastify-static. Since it did not work I started to think about using fastify@next to overcome routing issues...

But I just realized that another way might be to put everything served by fastify-static under it's own prefix. It seems better option from my perspective since it separates UI stuff from other plugin endpoints and should work with current dependencies. I will give it a try today.

@kromol kromol changed the title WIP: Support static files references Support static files references Dec 21, 2018
@kromol
Copy link
Contributor Author

kromol commented Jan 2, 2019

Happy New Year!
@mcollina pls review the PR when you get a chance

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd also need to add the new option to the type definition in https://github.com/fastify/fastify-swagger/blob/master/index.d.ts#L10 and a test for the typescript types.

t.error(err)
t.strictEqual(res.statusCode, 404)
})
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a test that checks that the Fastify not found handler is called? This is likely to fail/conflict on Fastify v2, and we need the test to make sure the behavior is consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

routes.js Outdated
const contentType = ext === '.yaml' ? 'application/x-yaml' : 'application/json'
reply
.type(contentType)
.send(fs.readFileSync(filePath))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better if you switch to fastify-static reply.sendFile() method. You can just add the decorator by passing { serve: false } when registering fastify-static.

You'll need to register two instances of fastify-static, one with { serve: false } to use inside this function, and one with { decorateReply: false } to serve the swagger-ui. The two instances should not conflict/error. 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@cemremengu cemremengu mentioned this pull request Jan 2, 2019
kromol added 3 commits January 3, 2019 13:54
…ileSync, added more tests, fixed docs, updated typings, ensure that custom NotFoundHandler is being called
@kromol
Copy link
Contributor Author

kromol commented Jan 3, 2019

Rebased my branch on the latest master, but did not squash commits yet for easier review

@cemremengu
Copy link
Contributor

@kromol you dont need to squash

@kromol
Copy link
Contributor Author

kromol commented Jan 3, 2019

Ok, great. I just thought that it should eventually be one commit per issue to keep history clean.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@cemremengu cemremengu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

routes.js Outdated
decorateReply: false
})

fastify.register(require('fastify-static'), {
Copy link
Member

@mcollina mcollina Jan 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You should probably move the require('fastify-static') at the top of the file in both instances.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, done.

@mcollina mcollina merged commit 43e4e85 into fastify:master Jan 4, 2019
@kromol kromol deleted the feature-#134/support-ref branch January 9, 2019 11:12
kromol pushed a commit to kromol/fastify-swagger that referenced this pull request Jan 9, 2019
Since we added prefix `/static` to separate swagger ui static files from other files we need to make sure that client wlll not use `/static` prefix for other calls (like for retrieving swagger.yaml)
kromol pushed a commit to kromol/fastify-swagger that referenced this pull request Jan 9, 2019
Since we added prefix `/static` to separate swagger ui static files from other files we need to make sure that client wlll not use `/static` prefix for other calls (like for retrieving swagger.yaml)
mcollina pushed a commit that referenced this pull request Jan 9, 2019
Since we added prefix `/static` to separate swagger ui static files from other files we need to make sure that client wlll not use `/static` prefix for other calls (like for retrieving swagger.yaml)
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 this pull request may close these issues.

None yet

3 participants