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

Upgrade to Fastify v5 #521

Merged
merged 1 commit into from
Oct 7, 2024
Merged
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
12 changes: 12 additions & 0 deletions .changeset/ninety-coats-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@zazuko/trifid-entity-renderer": minor
"trifid-plugin-graph-explorer": minor
"@zazuko/trifid-plugin-sparql-proxy": minor
"trifid-plugin-yasgui": minor
"@zazuko/trifid-plugin-ckan": minor
"trifid-core": minor
"@zazuko/trifid-plugin-iiif": minor
"trifid-plugin-spex": minor
---

Upgrade Fastify to v5.
369 changes: 207 additions & 162 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion packages/ckan/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ const factory = async (trifid) => {
* @param {import('fastify').FastifyReply} reply Reply.
*/
const handler = async (request, reply) => {
const fullUrl = `${request.protocol}://${request.hostname}${request.raw.url}`
let requestPort = `:${request.port}`
if ((request.protocol === 'http' && requestPort === ':80') || (request.protocol === 'https' && requestPort === ':443')) {
requestPort = ''
}
const fullUrl = `${request.protocol}://${request.hostname}${requestPort}${request.url}`
const endpoint = new URL(configuredEndpoint, fullUrl)
const { fetchDatasets, toXML } = createAPI({
endpointUrl: endpoint.toString(),
Expand Down
14 changes: 7 additions & 7 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@
"trifid-core": "./server.js"
},
"dependencies": {
"@fastify/accepts": "^4.3.0",
"@fastify/compress": "^7.0.3",
"@fastify/cookie": "^9.3.1",
"@fastify/cors": "^9.0.1",
"@fastify/formbody": "^7.4.0",
"@fastify/static": "^7.0.4",
"@fastify/accepts": "^5.0.1",
"@fastify/compress": "^8.0.1",
"@fastify/cookie": "^10.0.1",
"@fastify/cors": "^10.0.1",
"@fastify/formbody": "^8.0.1",
"@fastify/static": "^8.0.1",
"@fontsource/playfair-display": "^5.1.0",
"@fontsource/roboto": "^5.1.0",
"@rdfjs-elements/formats-pretty": "^0.6.7",
"@types/sparql-http-client": "^3.0.4",
"ajv": "^8.17.1",
"commander": "^12.1.0",
"fastify": "^4.28.1",
"fastify": "^5.0.0",
"handlebars": "^4.7.8",
"import-meta-resolve": "^4.1.0",
"json5": "^2.2.3",
Expand Down
6 changes: 5 additions & 1 deletion packages/entity-renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ const factory = async (trifid) => {
const acceptHeader = getAcceptHeader(request)

// Generate the IRI we expect
const fullUrl = `${request.protocol}://${request.hostname}${request.raw.url}`
let requestPort = `:${request.port}`
if ((request.protocol === 'http' && requestPort === ':80') || (request.protocol === 'https' && requestPort === ':443')) {
requestPort = ''
}
const fullUrl = `${request.protocol}://${request.hostname}${requestPort}${request.url}`
const iriUrl = new URL(fullUrl)
iriUrl.search = ''
iriUrl.searchParams.forEach((_value, key) => iriUrl.searchParams.delete(key))
Expand Down
6 changes: 5 additions & 1 deletion packages/graph-explorer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ const factory = async (trifid) => {
* @param {import('fastify').FastifyReply} reply Reply.
*/
const handler = async (request, reply) => {
const fullUrl = `${request.protocol}://${request.hostname}${request.raw.url}`
let requestPort = `:${request.port}`
if ((request.protocol === 'http' && requestPort === ':80') || (request.protocol === 'https' && requestPort === ':443')) {
requestPort = ''
}
const fullUrl = `${request.protocol}://${request.hostname}${requestPort}${request.url}`
const fullUrlObject = new URL(fullUrl)
const fullUrlPathname = fullUrlObject.pathname

Expand Down
2 changes: 1 addition & 1 deletion packages/graph-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"test": "c8 --all --reporter=lcovonly --reporter=text mocha"
},
"dependencies": {
"@fastify/static": "^7.0.4",
"@fastify/static": "^8.0.1",
"graph-explorer": "^1.2.0",
"import-meta-resolve": "^4.1.0"
},
Expand Down
6 changes: 5 additions & 1 deletion packages/iiif/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ const trifidFactory = async (trifid) => {
* @param {import('fastify').FastifyReply} reply Reply.
*/
const handler = async (request, reply) => {
const fullUrl = `${request.protocol}://${request.hostname}${request.raw.url}`
let requestPort = `:${request.port}`
if ((request.protocol === 'http' && requestPort === ':80') || (request.protocol === 'https' && requestPort === ':443')) {
requestPort = ''
}
const fullUrl = `${request.protocol}://${request.hostname}${requestPort}${request.url}`
const fullUrlObject = new URL(fullUrl)
const fullUrlPathname = fullUrlObject.pathname

Expand Down
27 changes: 21 additions & 6 deletions packages/sparql-proxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ const factory = async (trifid) => {
* @param {import('fastify').FastifyReply} reply Reply.
*/
const handler = async (request, reply) => {
const fullUrl = `${request.protocol}://${request.hostname}${request.raw.url}`
let requestPort = `:${request.port}`
if ((request.protocol === 'http' && requestPort === ':80') || (request.protocol === 'https' && requestPort === ':443')) {
requestPort = ''
}
const fullUrl = `${request.protocol}://${request.hostname}${requestPort}${request.url}`
const fullUrlObject = new URL(fullUrl)
const fullUrlPathname = fullUrlObject.pathname

Expand All @@ -165,6 +169,7 @@ const factory = async (trifid) => {

reply
.header('content-type', negotiatedType)
// @ts-ignore (cause: broken type definitions)
.send(await dataset.serialize({ format: negotiatedType }))
return reply
}
Expand Down Expand Up @@ -241,14 +246,22 @@ const factory = async (trifid) => {
}

const start = performance.now()
const response = await fetch(options.endpointUrl, {
let response = await fetch(options.endpointUrl, {
method: 'POST',
headers,
body: new URLSearchParams({ query }),
})
const end = performance.now()
const duration = end - start

if (!response) {
logger.warn('No response from the endpoint, make sure that the endpoint is reachable')
response = new Response(JSON.stringify({
success: false,
message: 'No response from the endpoint',
}), { status: 502, headers: { 'content-type': 'application/json' } })
}

const contentType = response.headers.get('content-type')

/** @type {any} */
Expand All @@ -265,12 +278,14 @@ const factory = async (trifid) => {
responseStream = Readable.fromWeb(responseStream)
}

reply
let proxyReply = reply
.status(response.status)
.header('Server-Timing', `sparql-proxy;dur=${duration};desc="Querying the endpoint"`)
.header('content-type', contentType)
.send(responseStream)
return reply
if (contentType) {
proxyReply = proxyReply.header('content-type', contentType)
}
proxyReply.send(responseStream)
return proxyReply
} catch (error) {
logger.error('Error while querying the endpoint')
logger.error(error)
Expand Down
2 changes: 1 addition & 1 deletion packages/sparql-proxy/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('sparql-proxy', () => {
const response = await rdf.fetch(`${url}/query?foo=bar`)

// then
expect(response.headers.get('content-type')).to.match(/text\/plain/)
expect(response.headers.get('content-type')).to.match(/^(text\/plain|application\/json).*/)
})

for (const [property] of forwardedProperties) {
Expand Down
6 changes: 5 additions & 1 deletion packages/spex/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ const createPlugin = async (server, config, render) => {
* @param {import('fastify').FastifyReply} reply Reply.
*/
const handler = async (request, reply) => {
const fullUrl = `${request.protocol}://${request.hostname}${request.raw.url}`
let requestPort = `:${request.port}`
if ((request.protocol === 'http' && requestPort === ':80') || (request.protocol === 'https' && requestPort === ':443')) {
requestPort = ''
}
const fullUrl = `${request.protocol}://${request.hostname}${requestPort}${request.url}`
const fullUrlObject = new URL(fullUrl)
const fullUrlPathname = fullUrlObject.pathname

Expand Down
2 changes: 1 addition & 1 deletion packages/spex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test": "c8 --all --reporter=lcovonly --reporter=text mocha"
},
"dependencies": {
"@fastify/static": "^7.0.4",
"@fastify/static": "^8.0.1",
"@zazuko/spex": "^0.2.1",
"import-meta-resolve": "^4.1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/yasgui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const trifidFactory = async (trifid) => {
* @param {import('fastify').FastifyReply} reply Reply.
*/
const handler = async (request, reply) => {
const fullUrl = `${request.protocol}://${request.hostname}${request.raw.url}`
const fullUrl = `${request.protocol}://${request.hostname}:${request.port}${request.url}`
const fullUrlObject = new URL(fullUrl)
const fullUrlPathname = fullUrlObject.pathname

Expand Down
2 changes: 1 addition & 1 deletion packages/yasgui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"test": "c8 --all --reporter=lcovonly --reporter=text mocha"
},
"dependencies": {
"@fastify/static": "^7.0.4",
"@fastify/static": "^8.0.1",
"@zazuko/yasgui": "^4.3.3",
"import-meta-resolve": "^4.1.0"
},
Expand Down