Skip to content

Commit

Permalink
add getMapStyleJsonUrl() method to MapeoManager
Browse files Browse the repository at this point in the history
  • Loading branch information
achou11 committed Jan 23, 2024
1 parent 7653a19 commit 649f766
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/mapeo-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const MAX_FILE_DESCRIPTORS = 768
// Prefix names for routes registered with http server
const BLOBS_PREFIX = 'blobs'
const ICONS_PREFIX = 'icons'
const MAPS_PREFIX = 'maps'

export const kRPC = Symbol('rpc')
export const kManagerReplicate = Symbol('replicate manager')
Expand Down Expand Up @@ -232,6 +233,10 @@ export class MapeoManager extends TypedEmitter {
prefix = ICONS_PREFIX
break
}
case 'maps': {
prefix = MAPS_PREFIX
break
}
default: {
throw new Error(`Unsupported media type ${mediaType}`)
}
Expand Down Expand Up @@ -761,6 +766,11 @@ export class MapeoManager extends TypedEmitter {

this.#activeProjects.delete(projectPublicId)
}

async getMapStyleJsonUrl() {
const mapsAddress = await this.#getMediaAddress('maps')
return mapsAddress + '/style.json'
}
}

// We use the `protomux` property of connected peers internally, but we don't
Expand Down
40 changes: 40 additions & 0 deletions test-e2e/manager-fastify-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,46 @@ test('retrieving icons using url', async (t) => {
await exceptionPromise2
})

test('retrieving style.json using url', async (t) => {
const clock = FakeTimers.install({ shouldAdvanceTime: true })
t.teardown(() => clock.uninstall())

const fastify = Fastify()
const fastifyController = new FastifyController({ fastify })
const manager = new MapeoManager({
rootKey: KeyManager.generateRootKey(),
projectMigrationsFolder,
clientMigrationsFolder,
dbFolder: ':memory:',
coreStorage: () => new RAM(),
fastify,
})

const exceptionPromise1 = t.exception(async () => {
await manager.getMapStyleJsonUrl()
}, 'cannot retrieve style json url before HTTP server starts')

clock.tick(100_000)
await exceptionPromise1

fastifyController.start({ port: 1234 })

const styleJsonUrl = await manager.getMapStyleJsonUrl()

t.ok(styleJsonUrl.endsWith(`:1234/maps/style.json`))

// TODO: Fetch style json using url and check response

await fastifyController.stop()

const exceptionPromise2 = t.exception(async () => {
await manager.getMapStyleJsonUrl()
}, 'cannot retrieve style json url after HTTP server closes')

clock.tick(100_000)
await exceptionPromise2
})

/**
* @param {string} url
*/
Expand Down

0 comments on commit 649f766

Please sign in to comment.