Skip to content

Commit

Permalink
Merge pull request #545 from zazuko/fix-request-port
Browse files Browse the repository at this point in the history
Handle null requestPort
  • Loading branch information
ludovicm67 authored Oct 22, 2024
2 parents 87b37bd + 724f2ed commit 827eea5
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 18 deletions.
10 changes: 10 additions & 0 deletions .changeset/funny-teachers-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@zazuko/trifid-entity-renderer": patch
"trifid-plugin-graph-explorer": patch
"@zazuko/trifid-plugin-sparql-proxy": patch
"@zazuko/trifid-plugin-ckan": patch
"@zazuko/trifid-plugin-iiif": patch
"trifid-plugin-spex": patch
---

Fix `requestPort` value, to handle `null` cases and simplify the logic
6 changes: 3 additions & 3 deletions packages/ckan/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ const factory = async (trifid) => {
* @param {import('fastify').FastifyReply} reply Reply.
*/
const handler = async (request, reply) => {
let requestPort = `:${request.port}`
if ((request.protocol === 'http' && requestPort === ':80') || (request.protocol === 'https' && requestPort === ':443')) {
requestPort = ''
let requestPort = ''
if (request.port) {
requestPort = `:${request.port}`
}
const fullUrl = `${request.protocol}://${request.hostname}${requestPort}${request.url}`
const endpoint = new URL(configuredEndpoint, fullUrl)
Expand Down
6 changes: 3 additions & 3 deletions packages/entity-renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ const factory = async (trifid) => {
const acceptHeader = getAcceptHeader(request)

// Generate the IRI we expect
let requestPort = `:${request.port}`
if ((request.protocol === 'http' && requestPort === ':80') || (request.protocol === 'https' && requestPort === ':443')) {
requestPort = ''
let requestPort = ''
if (request.port) {
requestPort = `:${request.port}`
}
const fullUrl = `${request.protocol}://${request.hostname}${requestPort}${request.url}`
const iriUrl = new URL(fullUrl)
Expand Down
6 changes: 3 additions & 3 deletions packages/graph-explorer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ const factory = async (trifid) => {
* @param {import('fastify').FastifyReply} reply Reply.
*/
const handler = async (request, reply) => {
let requestPort = `:${request.port}`
if ((request.protocol === 'http' && requestPort === ':80') || (request.protocol === 'https' && requestPort === ':443')) {
requestPort = ''
let requestPort = ''
if (request.port) {
requestPort = `:${request.port}`
}
const fullUrl = `${request.protocol}://${request.hostname}${requestPort}${request.url}`
const fullUrlObject = new URL(fullUrl)
Expand Down
6 changes: 3 additions & 3 deletions packages/iiif/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ const trifidFactory = async (trifid) => {
* @param {import('fastify').FastifyReply} reply Reply.
*/
const handler = async (request, reply) => {
let requestPort = `:${request.port}`
if ((request.protocol === 'http' && requestPort === ':80') || (request.protocol === 'https' && requestPort === ':443')) {
requestPort = ''
let requestPort = ''
if (request.port) {
requestPort = `:${request.port}`
}
const fullUrl = `${request.protocol}://${request.hostname}${requestPort}${request.url}`
const fullUrlObject = new URL(fullUrl)
Expand Down
6 changes: 3 additions & 3 deletions packages/sparql-proxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ const factory = async (trifid) => {
* @param {import('fastify').FastifyReply} reply Reply.
*/
const handler = async (request, reply) => {
let requestPort = `:${request.port}`
if ((request.protocol === 'http' && requestPort === ':80') || (request.protocol === 'https' && requestPort === ':443')) {
requestPort = ''
let requestPort = ''
if (request.port) {
requestPort = `:${request.port}`
}
const fullUrl = `${request.protocol}://${request.hostname}${requestPort}${request.url}`
const fullUrlObject = new URL(fullUrl)
Expand Down
6 changes: 3 additions & 3 deletions packages/spex/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ const createPlugin = async (server, config, render) => {
* @param {import('fastify').FastifyReply} reply Reply.
*/
const handler = async (request, reply) => {
let requestPort = `:${request.port}`
if ((request.protocol === 'http' && requestPort === ':80') || (request.protocol === 'https' && requestPort === ':443')) {
requestPort = ''
let requestPort = ''
if (request.port) {
requestPort = `:${request.port}`
}
const fullUrl = `${request.protocol}://${request.hostname}${requestPort}${request.url}`
const fullUrlObject = new URL(fullUrl)
Expand Down

0 comments on commit 827eea5

Please sign in to comment.