diff --git a/src/plugins/share/server/routes/goto.ts b/src/plugins/share/server/routes/goto.ts index 7343dc1bd34a26..34c8e82588dd69 100644 --- a/src/plugins/share/server/routes/goto.ts +++ b/src/plugins/share/server/routes/goto.ts @@ -23,6 +23,15 @@ import { schema } from '@kbn/config-schema'; import { shortUrlAssertValid } from './lib/short_url_assert_valid'; import { ShortUrlLookupService } from './lib/short_url_lookup'; +const makeUrlEmbeddable = (url: string): string => { + const embedQueryParam = '?embed=true'; + const urlHasQueryString = url.indexOf('?') !== -1; + if (urlHasQueryString) { + return url.replace('?', `${embedQueryParam}&`); + } + return `${url}${embedQueryParam}`; +}; + export const createGotoRoute = ({ router, shortUrlLookup, @@ -37,14 +46,21 @@ export const createGotoRoute = ({ path: '/goto/{urlId}', validate: { params: schema.object({ urlId: schema.string() }), + query: schema.maybe( + schema.object({ + embed: schema.maybe(schema.oneOf([schema.string(), schema.literal(null)])), + }) + ), }, }, router.handleLegacyErrors(async function(context, request, response) { - const url = await shortUrlLookup.getUrl(request.params.urlId, { + let url = await shortUrlLookup.getUrl(request.params.urlId, { savedObjects: context.core.savedObjects.client, }); shortUrlAssertValid(url); - + if (request.query && request.query.embed && request.query.embed === 'true') { + url = makeUrlEmbeddable(url); + } const uiSettings = context.core.uiSettings.client; const stateStoreInSessionStorage = await uiSettings.get('state:storeInSessionStorage'); if (!stateStoreInSessionStorage) {