File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
packages/playground/website/src Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 1+ import { oAuthState } from './state' ;
2+
3+ const KNOWN_CORS_PROXY_URLS = [
4+ 'https://playground.wordpress.net/cors-proxy.php?' ,
5+ 'https://wordpress-playground-cors-proxy.net/?' ,
6+ 'http://127.0.0.1:5263/cors-proxy.php?' ,
7+ ] ;
8+
9+ export function isGitHubUrl ( url : string ) : boolean {
10+ if ( url . includes ( 'github.com' ) ) {
11+ return true ;
12+ }
13+ for ( const corsProxyUrl of KNOWN_CORS_PROXY_URLS ) {
14+ if (
15+ url . startsWith ( corsProxyUrl ) &&
16+ url . substring ( corsProxyUrl . length ) . includes ( 'github.com' )
17+ ) {
18+ return true ;
19+ }
20+ }
21+ return false ;
22+ }
23+
24+ export function createGitHubAuthHeaders ( ) : Record < string , string > {
25+ const token = oAuthState . value . token ;
26+ if ( ! token ) {
27+ return { } ;
28+ }
29+
30+ return {
31+ Authorization : `Basic ${ btoa ( `${ token } :` ) } ` ,
32+ // Tell the CORS proxy to forward the Authorization header
33+ 'X-Cors-Proxy-Allowed-Request-Headers' : 'Authorization' ,
34+ } ;
35+ }
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ import { selectSiteBySlug } from './slice-sites';
2727// @ts -ignore
2828import { corsProxyUrl } from 'virtual:cors-proxy-url' ;
2929import { modalSlugs } from '../../../components/layout' ;
30- import { createGitHubAuthHeaders } from '../../github/git-auth-helpers' ;
30+ import { createGitHubAuthHeaders } from '../../../ github/git-auth-helpers' ;
3131
3232export function bootSiteClient (
3333 siteSlug : string ,
You can’t perform that action at this time.
0 commit comments