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

Fix: redirect to index #67

Merged
merged 5 commits into from
May 9, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"devDependencies": {
"fastify": "^1.3.1",
"fs-extra": "^6.0.0",
"pre-commit": "^1.2.2",
"standard": "^11.0.0",
"swagger-parser": "^4.1.0",
"swagger-ui-dist": "3.14.0",
Expand Down
2 changes: 1 addition & 1 deletion routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function fastifySwagger (fastify, opts, next) {
url: '/',
method: 'GET',
schema: { hide: true },
handler: (request, reply) => reply.redirect(`.${opts.prefix}/`)
handler: (request, reply) => reply.redirect(`${opts.prefix}/index.html`)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that opts.prefix here is correct. Can you add a test that loads this within another plugin, so that this is exposed as /v1/documentation? I think it should use fastify.basePath.

Copy link
Member Author

Choose a reason for hiding this comment

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

nice catch!! fixed

})

fastify.route({
Expand Down
4 changes: 2 additions & 2 deletions test/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ test('fastify.swagger should return a valid swagger yaml', t => {
})
})

test('/documentation should redirect to /documentation/', t => {
test('/documentation should redirect to /documentation/index.html', t => {
t.plan(4)
const fastify = Fastify()
fastify.register(fastifySwagger, swaggerInfo)
Expand All @@ -183,7 +183,7 @@ test('/documentation should redirect to /documentation/', t => {
}, (err, res) => {
t.error(err)
t.strictEqual(res.statusCode, 302)
t.strictEqual(res.headers['location'], './documentation/')
t.strictEqual(res.headers['location'], '/documentation/index.html')
t.is(typeof res.payload, 'string')
})
})
Expand Down