Skip to content

Commit

Permalink
fix: wrong hostname containing port #398
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab authored and frodrigo committed Oct 25, 2024
1 parent ae0af90 commit f92a72c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
12 changes: 4 additions & 8 deletions server/routes/manifest.webmanifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@ import { defineEventHandler } from 'h3'
import { getSettings } from '../../lib/apiSettings'
import { vidos } from '../../lib/config'
import { vidoConfigResolve } from '../../plugins/vido-config'
import type { VidoConfig } from '../../utils/types-config'

async function manifest(
req: IncomingMessage,
res: ServerResponse<IncomingMessage>,
) {
const hostname = (req.headers['x-forwarded-host'] || req.headers.host) as
| string
| undefined
if (hostname) {
const vido: VidoConfig = vidoConfigResolve(hostname, vidos())
const fetchSettings = getSettings(vido)
const hostname = (req.headers['x-forwarded-host'] || req.headers.host)?.toString().split(':')[0]

const [settings] = await Promise.all([fetchSettings])
if (hostname) {
const vido = vidoConfigResolve(hostname, vidos())
const settings = await getSettings(vido)

res.write(
JSON.stringify({
Expand Down
18 changes: 7 additions & 11 deletions server/routes/sitemap.xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,25 @@ import { getMenu } from '~/lib/apiMenu'
import { getPois } from '~/lib/apiPois'
import { vidos } from '~/lib/config'
import { vidoConfigResolve } from '~/plugins/vido-config'
import type { VidoConfig } from '~/utils/types-config'

// Import by node_modules because access to internal module content

async function manifest(
req: IncomingMessage,
res: ServerResponse<IncomingMessage>,
) {
const hostname = (req.headers['x-forwarded-host'] || req.headers.host) as
| string
| undefined
const hostname = (req.headers['x-forwarded-host'] || req.headers.host)?.toString()

if (hostname) {
const vido: VidoConfig = vidoConfigResolve(hostname, vidos())
const vido = vidoConfigResolve(hostname.split(':')[0], vidos())

const menu = getMenu(vido).then(menuItem =>
menuItem
const menu = getMenu(vido)
.then(menuItem => menuItem
.filter(menuItem => menuItem.category && menuItem.id)
.map(menuCategory => ({
url: `/${menuCategory.id}/`,
})),
)
)

const pois = getPois(vido).then(apiPois =>
apiPois.features.map(poi => ({
Expand All @@ -41,9 +39,7 @@ async function manifest(
})),
)

const entries: SitemapEntry[] = (await Promise.all([menu, pois])).flat(
1,
)
const entries: SitemapEntry[] = (await Promise.all([menu, pois])).flat(1)

entries.push({
url: '/',
Expand Down

0 comments on commit f92a72c

Please sign in to comment.