File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed
Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,8 @@ import { projectOutputDir } from "../../project/project-shared.ts";
7474import { projectContext } from "../../project/project-context.ts" ;
7575import { normalizePath , pathWithForwardSlashes } from "../../core/path.ts" ;
7676import {
77+ gitHubCodeSpacesProxyUri ,
78+ isGitHubCodespaces ,
7779 isJupyterHubServer ,
7880 isRStudioServer ,
7981 isRStudioWorkbench ,
@@ -750,6 +752,9 @@ function pdfFileRequestHandler(
750752 : isVSCodeServer ( )
751753 ? vsCodeServerProxyUri ( ) ! . replace ( "{{port}}" , `${ port } ` ) +
752754 kPdfJsInitialPath
755+ : isGitHubCodespaces ( )
756+ ? gitHubCodeSpacesProxyUri ( ) ! . replace ( "{{port}}" , `${ port } ` ) +
757+ kPdfJsInitialPath
753758 : "/" + kPdfJsInitialPath ;
754759 return Promise . resolve ( serveRedirect ( url ) ) ;
755760 } else {
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ import { resourceFilesFromRenderedFile } from "./resources.ts";
2121import { RenderFlags , RenderOptions , RenderResult } from "./types.ts" ;
2222import { fileExecutionEngine } from "../../execute/engine.ts" ;
2323import {
24+ gitHubCodeSpacesProxyUri ,
25+ isGitHubCodespaces ,
2426 isJupyterHubServer ,
2527 isJupyterServer ,
2628 isRStudioServer ,
@@ -188,6 +190,10 @@ export async function printBrowsePreviewMessage(
188190 const browseUrl = proxyUrl . replace ( "{{port}}" , `${ port } ` ) +
189191 path ;
190192 info ( `\nBrowse at ${ browseUrl } ` , { format : colors . green } ) ;
193+ } else if ( isVSCodeTerminal ( ) && isGitHubCodespaces ( ) ) {
194+ const browseUrl =
195+ gitHubCodeSpacesProxyUri ( ) ! . replace ( "{{port}}" , `${ port } ` ) + path ;
196+ info ( `\nBrowse at ${ browseUrl } ` , { format : colors . green } ) ;
191197 } else if ( isJupyterHubServer ( ) ) {
192198 const httpReferrer = `${
193199 jupyterHubHttpReferrer ( ) || "<jupyterhub-server-url>/"
Original file line number Diff line number Diff line change @@ -33,6 +33,29 @@ export function isVSCodeTerminal() {
3333 return Deno . env . get ( "TERM_PROGRAM" ) === "vscode" ;
3434}
3535
36+ export function gitHubCodespaceName ( ) {
37+ return Deno . env . get ( "CODESPACE_NAME" ) ;
38+ }
39+
40+ export function gitHubCodespacePortForwardingDomain ( ) {
41+ return Deno . env . get ( "GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN" ) ;
42+ }
43+
44+ export function isGitHubCodespaces ( ) {
45+ return ! ! gitHubCodespacePortForwardingDomain ( ) || ! ! gitHubCodespaceName ( ) ;
46+ }
47+
48+ export function gitHubCodeSpacesProxyUri ( ) {
49+ const CODESPACE_NAME = gitHubCodespaceName ( ) ;
50+ const GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN =
51+ gitHubCodespacePortForwardingDomain ( ) ;
52+ if ( CODESPACE_NAME && GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN ) {
53+ return `https://${ CODESPACE_NAME } -{{port}}.${ GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN } ` ;
54+ } else {
55+ return undefined ;
56+ }
57+ }
58+
3659export function isVSCodeServer ( ) {
3760 return ! ! vsCodeServerProxyUri ( ) ;
3861}
You can’t perform that action at this time.
0 commit comments