@@ -16,6 +16,7 @@ function getHostname(event, context) {
1616 return JSON . parse ( Buffer . from ( netlify , 'base64' ) . toString ( 'utf-8' ) ) . site_url ;
1717}
1818
19+ const PROVIDER = 'testing-playground.com' ;
1920const allowedPathsRegexp = new RegExp ( / ^ \/ ( g i s t | e m b e d ) \/ .* / ) ;
2021
2122function handler ( event , context , callback ) {
@@ -38,22 +39,28 @@ function handler(event, context, callback) {
3839 ) ;
3940 }
4041
41- const { hostname , pathname } = new URL ( params . url ) ;
42+ const url = new URL ( params . url ) ;
4243
4344 // verify if the url is supported, basically we only allow localhost if we're
4445 // running at localhost, and testing-playground.com as host. And either no
4546 // path or /gist and /embed paths.
4647 if (
47- ( ! host . includes ( hostname ) && hostname !== 'testing-playground.com' ) ||
48- ( pathname && ! allowedPathsRegexp . test ( pathname ) )
48+ ( ! host . includes ( url . hostname ) && url . hostname !== PROVIDER ) ||
49+ ( url . pathname !== '/' && ! allowedPathsRegexp . test ( url . pathname ) )
4950 ) {
5051 return callback ( null , incorrectParams ( 'unsupported url provided :/' ) ) ;
5152 }
5253
53- // map /gist urls to /embed
54- const url = pathname . startsWith ( '/gist/' )
55- ? params . url . replace ( '/gist/' , '/embed/' )
56- : params . url ;
54+ // map / and /gist to /embed
55+ url . pathname =
56+ url . pathname === '/'
57+ ? '/embed'
58+ : url . pathname . replace ( / ^ \/ g i s t \/ / , '/embed/' ) ;
59+
60+ // set default panes if no panes are provided, KEEP IN SYNC WITH /constants#defaultPanes !
61+ if ( ! url . searchParams . has ( 'panes' ) ) {
62+ url . searchParams . set ( 'panes' , 'query,preview' ) ;
63+ }
5764
5865 callback ( null , {
5966 statusCode : 200 ,
@@ -63,7 +70,7 @@ function handler(event, context, callback) {
6370 type : 'rich' ,
6471 success : true ,
6572
66- provider_name : 'testing-playground.com' ,
73+ provider_name : PROVIDER ,
6774 provider_url : host ,
6875
6976 html : `<iframe src="${ url } " height="${ maxheight } " width="${ maxwidth } " scrolling="no" frameBorder="0" allowTransparency="true" title="Testing Playground" style="overflow: hidden; display: block; width: 100%"></iframe>` ,
0 commit comments