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

chore: protect individual certificate endpoint with token #1097

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
36 changes: 4 additions & 32 deletions src/data-seeding/certificates/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,8 @@ import { Request, ResponseToolkit } from '@hapi/hapi'
import { readFileSync } from 'fs'

export async function certificateHandler(request: Request, h: ResponseToolkit) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's move this endpoint outside data-seeding directory altogether

if (request.params.event) {
const res = readFileSync(
`./src/data-seeding/certificates/source/Farajaland-${request.params.event}-certificate-v2.svg`
).toString()
return h.response(res).code(200)
}

const Certificates = [
{
event: 'birth',
fileName: 'Farajaland-birth-certificate-v2.svg',
svgCode: readFileSync(
'./src/data-seeding/certificates/source/Farajaland-birth-certificate-v2.svg'
).toString()
},
{
event: 'death',
fileName: 'Farajaland-death-certificate-v2.svg',
svgCode: readFileSync(
'./src/data-seeding/certificates/source/Farajaland-death-certificate-v2.svg'
).toString()
},
{
event: 'marriage',
fileName: 'Farajaland-marriage-certificate-v2.svg',
svgCode: readFileSync(
'./src/data-seeding/certificates/source/Farajaland-marriage-certificate-v2.svg'
).toString()
}
]
const res = JSON.stringify(Certificates)
return h.response(res)
const res = readFileSync(
`./src/data-seeding/certificates/source/Farajaland-${request.params.event}-certificate-v2.svg`
).toString()
return h.response(res).code(200)
}
31 changes: 9 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,15 @@ export async function createServer() {

server.auth.default('jwt')

if (process.env.NODE_ENV !== 'production') {
server.route({
method: 'GET',
path: '/certificates/{event}.svg',
handler: certificateHandler,
options: {
auth: false,
tags: ['api', 'certificates'],
description: 'Returns only one certificate metadata'
}
})
}
server.route({
method: 'GET',
path: '/certificates/{event}.svg',
handler: certificateHandler,
options: {
tags: ['api', 'certificates'],
description: 'Returns only one certificate metadata'
}
})
// add ping route by default for health check
server.route({
method: 'GET',
Expand Down Expand Up @@ -501,16 +498,6 @@ export async function createServer() {
}
})

server.route({
method: 'GET',
path: '/certificates',
handler: certificateHandler,
options: {
tags: ['api', 'certificates'],
description: 'Returns certificate metadata'
}
})

server.route({
method: 'GET',
path: '/roles',
Expand Down
Loading