@@ -16,6 +16,7 @@ function getHostname(event, context) {
16
16
return JSON . parse ( Buffer . from ( netlify , 'base64' ) . toString ( 'utf-8' ) ) . site_url ;
17
17
}
18
18
19
+ const PROVIDER = 'testing-playground.com' ;
19
20
const allowedPathsRegexp = new RegExp ( / ^ \/ ( g i s t | e m b e d ) \/ .* / ) ;
20
21
21
22
function handler ( event , context , callback ) {
@@ -38,22 +39,28 @@ function handler(event, context, callback) {
38
39
) ;
39
40
}
40
41
41
- const { hostname , pathname } = new URL ( params . url ) ;
42
+ const url = new URL ( params . url ) ;
42
43
43
44
// verify if the url is supported, basically we only allow localhost if we're
44
45
// running at localhost, and testing-playground.com as host. And either no
45
46
// path or /gist and /embed paths.
46
47
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 ) )
49
50
) {
50
51
return callback ( null , incorrectParams ( 'unsupported url provided :/' ) ) ;
51
52
}
52
53
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
+ }
57
64
58
65
callback ( null , {
59
66
statusCode : 200 ,
@@ -63,7 +70,7 @@ function handler(event, context, callback) {
63
70
type : 'rich' ,
64
71
success : true ,
65
72
66
- provider_name : 'testing-playground.com' ,
73
+ provider_name : PROVIDER ,
67
74
provider_url : host ,
68
75
69
76
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