Skip to content
Snippets Groups Projects
Commit 0c283ea5 authored by michael.kainz's avatar michael.kainz Committed by julian.baeume
Browse files

Consider APP_ROOT

parent fe8ffe14
No related branches found
No related tags found
No related merge requests found
......@@ -133,14 +133,14 @@ describe('Service delivers a generated web-manifest', function () {
})
const response = await request(app.server).get('/pwa.json').set('host', 'ui-server')
expect(response.statusCode).to.equal(500)
expect(response.text).to.have.string('Failed to load config for url ui-server: Error:')
expect(response.text).to.have.string('Failed to load config for url https://ui-server/pwa.json: Error:')
})
it('must not deliver a manifest with invalid host', async function () {
const app = await mockApp()
const response = await request(app.server).get('/pwa.json').set('host', 'ui-server-not')
expect(response.statusCode).to.equal(500)
expect(response.text).to.equal('Failed to load config for url ui-server-not: Error: Failed to fetch https://ui-server-not/api/apps/manifests?action=config')
expect(response.text).to.equal('Failed to load config for url https://ui-server-not/pwa.json: Error: Failed to fetch https://ui-server-not/api/apps/manifests?action=config')
})
it('delivers valid webmanifest with raw_manifest', async function () {
......@@ -219,7 +219,7 @@ describe('Service delivers a generated web-manifest', function () {
})
const response = await request(app.server).get('/pwa.json').set('host', 'ui-server')
expect(response.statusCode).to.equal(500)
expect(response.text).to.have.string('Failed to load config for url ui-server: Error:')
expect(response.text).to.have.string('Failed to load config for url https://ui-server/pwa.json: Error:')
})
it('must choose raw_manifest over short syntax', async function () {
......
......@@ -80,7 +80,7 @@ export async function createApp (basePath) {
}
await app.register(serveFilePlugin)
await app.register(serveWebmanifest)
await app.register(serveWebmanifest, { prefix: process.env.APP_ROOT })
return app
}
......@@ -32,21 +32,23 @@ const template = {
export default async function serveWebmanifest (fastify) {
fastify.get('/pwa.json', async (req, res) => {
const hostname = req.hostname
const urlData = req.urlData()
const url = `https://${urlData.host}${urlData.path}`
try {
const cached = await get(getRedisKey({ name: `cachedManifest:${hostname}` }), async () => [await fetchWebManifest(hostname), 86400])
const cached = await get(getRedisKey({ name: `cachedManifest:${url}` }), async () => [await fetchWebManifest(url), 86400])
res.type('application/manifest+json')
res.send(cached)
} catch (err) {
res.statusCode = 500
res.send(`Failed to load config for url ${hostname}: ${err}`)
res.send(`Failed to load config for url ${url}: ${err}`)
}
})
}
async function fetchWebManifest (hostname) {
const url = new URL('/api/apps/manifests?action=config', 'https://' + hostname)
const conf = await fetch(url)
async function fetchWebManifest (url) {
const serverConfigURL = new URL('/api/apps/manifests?action=config', url)
const conf = await fetch(serverConfigURL)
if (conf.ok) {
const data = (await conf.json()).data
......@@ -60,7 +62,7 @@ async function fetchWebManifest (hostname) {
const webmanifest = JSON.stringify(combinedManifest, null, 2)
return webmanifest
} else {
throw new Error(`Failed to fetch ${url}`)
throw new Error(`Failed to fetch ${serverConfigURL}`)
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment