Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gzupanda
code-server
提交
bf1be16d
C
code-server
项目概览
gzupanda
/
code-server
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
code-server
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
bf1be16d
编写于
2月 13, 2020
作者:
A
Asher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix base path
Now it should work whether you have a trailing slash or not.
上级
cc79edb3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
50 addition
and
36 deletion
+50
-36
src/browser/app.tsx
src/browser/app.tsx
+14
-4
src/node/http.ts
src/node/http.ts
+12
-9
src/node/vscode/server.ts
src/node/vscode/server.ts
+2
-0
src/node/vscode/workbench-build.html
src/node/vscode/workbench-build.html
+14
-16
src/node/vscode/workbench.html
src/node/vscode/workbench.html
+8
-7
未找到文件。
src/browser/app.tsx
浏览文件 @
bf1be16d
import
{
field
,
logger
}
from
"
@coder/logger
"
import
{
getBasepath
,
navigate
,
setBasepath
}
from
"
hookrouter
"
import
*
as
React
from
"
react
"
import
{
Application
,
isExecutableApplication
}
from
"
../common/api
"
...
...
@@ -14,16 +15,25 @@ interface RedirectedApplication extends Application {
redirected
?:
boolean
}
const
origin
=
typeof
window
!==
"
undefined
"
?
window
.
location
.
origin
+
window
.
location
.
pathname
:
undefined
let
resolved
=
false
const
App
:
React
.
FunctionComponent
<
AppProps
>
=
(
props
)
=>
{
const
[
authed
,
setAuthed
]
=
React
.
useState
<
boolean
>
(
props
.
options
.
authed
)
const
[
app
,
setApp
]
=
React
.
useState
<
RedirectedApplication
|
undefined
>
(
props
.
options
.
app
)
const
[
error
,
setError
]
=
React
.
useState
<
HttpError
|
Error
|
string
>
()
if
(
typeof
window
!==
"
undefined
"
)
{
const
url
=
new
URL
(
origin
+
props
.
options
.
basePath
)
if
(
!
resolved
&&
typeof
document
!==
"
undefined
"
)
{
// Get the base path. We need the full URL for connecting the web socket.
// Use the path name plus the provided base path. For example:
// foo.com/base + ./ => foo.com/base
// foo.com/base/ + ./ => foo.com/base
// foo.com/base/bar + ./ => foo.com/base
// foo.com/base/bar/ + ./../ => foo.com/base
const
parts
=
window
.
location
.
pathname
.
replace
(
/^
\/
/g
,
""
).
split
(
"
/
"
)
parts
[
parts
.
length
-
1
]
=
props
.
options
.
basePath
const
url
=
new
URL
(
window
.
location
.
origin
+
"
/
"
+
parts
.
join
(
"
/
"
))
setBasepath
(
normalize
(
url
.
pathname
))
logger
.
debug
(
"
resolved base path
"
,
field
(
"
base
"
,
getBasepath
()))
resolved
=
true
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(
window
as
any
).
setAuthed
=
(
a
:
boolean
):
void
=>
{
...
...
src/node/http.ts
浏览文件 @
bf1be16d
...
...
@@ -117,8 +117,9 @@ interface ProviderRoute extends Route {
export
interface
HttpProviderOptions
{
readonly
auth
:
AuthType
readonly
password
?
:
string
readonly
base
:
string
readonly
commit
:
string
readonly
password
?:
string
}
/**
...
...
@@ -150,10 +151,16 @@ export abstract class HttpProvider {
public
abstract
handleRequest
(
route
:
Route
,
request
:
http
.
IncomingMessage
):
Promise
<
HttpResponse
|
undefined
>
/**
* Get the base relative to the provided route.
* Get the base relative to the provided route. For each slash we need to go
* up a directory. For example:
* / => ./
* /foo => ./
* /foo/ => ./../
* /foo/bar => ./../
* /foo/bar/ => ./../../
*/
public
base
(
route
:
Route
):
string
{
const
depth
=
(
(
route
.
fullPath
+
"
/
"
)
.
match
(
/
\/
/g
)
||
[]).
length
const
depth
=
(
route
.
originalPath
.
match
(
/
\/
/g
)
||
[]).
length
return
normalize
(
"
./
"
+
(
depth
>
1
?
"
../
"
.
repeat
(
depth
-
1
)
:
""
))
}
...
...
@@ -403,6 +410,7 @@ export class HttpServer {
new
provider
(
{
auth
:
this
.
options
.
auth
||
AuthType
.
None
,
base
:
`/
${
endpoint
}
`
,
commit
:
this
.
options
.
commit
,
password
:
this
.
options
.
password
,
},
...
...
@@ -510,11 +518,6 @@ export class HttpServer {
return
{
redirect
:
redirect
(
route
.
fullPath
)
}
}
// Redirect our indexes to a trailing slash so relative paths in the served
// HTML will operate against the base path properly.
if
(
route
.
requestPath
===
"
/index.html
"
&&
!
route
.
originalPath
.
endsWith
(
"
/
"
)
&&
this
.
providers
.
has
(
route
.
base
))
{
return
{
redirect
:
redirect
(
route
.
fullPath
+
"
/
"
)
}
}
return
undefined
}
...
...
@@ -572,7 +575,7 @@ export class HttpServer {
}
const
parsedUrl
=
request
.
url
?
url
.
parse
(
request
.
url
,
true
)
:
{
query
:
{},
pathname
:
""
}
const
originalPath
=
parsedUrl
.
pathname
||
""
const
originalPath
=
parsedUrl
.
pathname
||
"
/
"
const
fullPath
=
normalize
(
originalPath
)
const
{
base
,
requestPath
}
=
parse
(
fullPath
)
...
...
src/node/vscode/server.ts
浏览文件 @
bf1be16d
...
...
@@ -199,6 +199,8 @@ export class VscodeHttpProvider extends HttpProvider {
...
response
,
content
:
response
.
content
.
replace
(
/{{COMMIT}}/g
,
options
.
commit
)
.
replace
(
/{{BASE}}/g
,
this
.
base
(
route
))
.
replace
(
/{{VS_BASE}}/g
,
this
.
base
(
route
)
+
this
.
options
.
base
)
.
replace
(
`"{{REMOTE_USER_DATA_URI}}"`
,
`'
${
JSON
.
stringify
(
options
.
remoteUserDataUri
)}
'`
)
.
replace
(
`"{{PRODUCT_CONFIGURATION}}"`
,
`'
${
JSON
.
stringify
(
options
.
productConfiguration
)}
'`
)
.
replace
(
`"{{WORKBENCH_WEB_CONFIGURATION}}"`
,
`'
${
JSON
.
stringify
(
options
.
workbenchWebConfiguration
)}
'`
)
...
...
src/node/vscode/workbench-build.html
浏览文件 @
bf1be16d
...
...
@@ -19,28 +19,27 @@
<meta
id=
"vscode-remote-nls-configuration"
data-settings=
"{{NLS_CONFIGURATION}}"
>
<!-- Workbench Icon/Manifest/CSS -->
<link
rel=
"icon"
href=
"
..
/static-{{COMMIT}}/src/browser/media/favicon.ico"
type=
"image/x-icon"
/>
<link
rel=
"manifest"
href=
"
..
/static-{{COMMIT}}/src/browser/media/manifest.json"
crossorigin=
"use-credentials"
>
<link
data-name=
"vs/workbench/workbench.web.api"
rel=
"stylesheet"
href=
"
.
/static-{{COMMIT}}/out/vs/workbench/workbench.web.api.css"
>
<link
rel=
"apple-touch-icon"
href=
"
..
/static-{{COMMIT}}/src/browser/media/code-server.png"
/>
<link
rel=
"icon"
href=
"
{{BASE}}
/static-{{COMMIT}}/src/browser/media/favicon.ico"
type=
"image/x-icon"
/>
<link
rel=
"manifest"
href=
"
{{BASE}}
/static-{{COMMIT}}/src/browser/media/manifest.json"
crossorigin=
"use-credentials"
>
<link
data-name=
"vs/workbench/workbench.web.api"
rel=
"stylesheet"
href=
"
{{VS_BASE}}
/static-{{COMMIT}}/out/vs/workbench/workbench.web.api.css"
>
<link
rel=
"apple-touch-icon"
href=
"
{{BASE}}
/static-{{COMMIT}}/src/browser/media/code-server.png"
/>
<meta
name=
"apple-mobile-web-app-capable"
content=
"yes"
>
<!-- Prefetch to avoid waterfall -->
<link
rel=
"prefetch"
href=
"
.
/static-{{COMMIT}}/node_modules/semver-umd/lib/semver-umd.js"
>
<link
rel=
"prefetch"
href=
"
{{BASE}}
/static-{{COMMIT}}/node_modules/semver-umd/lib/semver-umd.js"
>
</head>
<body
aria-label=
""
>
</body>
<!-- Startup (do not modify order of script tags!) -->
<!-- NOTE:coder: Modified to work against the current path and use the commit for caching. -->
<script>
// NOTE: Changes to inline scripts require update of content security policy
const
basePath
=
window
.
location
.
pathname
.
replace
(
/
\/
+$/
,
''
);
const
base
=
window
.
location
.
origin
+
basePath
;
const
parts
=
window
.
location
.
pathname
.
replace
(
/^
\/
/g
,
""
).
split
(
"
/
"
)
parts
[
parts
.
length
-
1
]
=
"
{{VS_BASE}}
"
const
url
=
new
URL
(
window
.
location
.
origin
+
"
/
"
+
parts
.
join
(
"
/
"
))
const
el
=
document
.
getElementById
(
'
vscode-remote-commit
'
);
const
commit
=
el
?
el
.
getAttribute
(
'
data-settings
'
)
:
""
;
const
staticBase
=
base
+
'
/static-
'
+
commit
;
const
staticBase
=
url
.
href
+
'
/static-
'
+
commit
;
let
nlsConfig
;
try
{
nlsConfig
=
JSON
.
parse
(
document
.
getElementById
(
'
vscode-remote-nls-configuration
'
).
getAttribute
(
'
data-settings
'
));
...
...
@@ -54,7 +53,7 @@
// FIXME: Only works if path separators are /.
const
path
=
nlsConfig
.
_resolvedLanguagePackCoreLocation
+
'
/
'
+
bundle
.
replace
(
/
\/
/g
,
'
!
'
)
+
'
.nls.json
'
;
fetch
(
`
${
base
}
/resource/?path=
${
encodeURIComponent
(
path
)}
`
)
fetch
(
`
${
url
.
href
}
/resource/?path=
${
encodeURIComponent
(
path
)}
`
)
.
then
((
response
)
=>
response
.
json
())
.
then
((
json
)
=>
{
bundles
[
bundle
]
=
json
;
...
...
@@ -78,15 +77,14 @@
'
vs/nls
'
:
nlsConfig
,
};
</script>
<script
src=
"
.
/static-{{COMMIT}}/out/vs/loader.js"
></script>
<script
src=
"
.
/static-{{COMMIT}}/out/vs/workbench/workbench.web.api.nls.js"
></script>
<script
src=
"
.
/static-{{COMMIT}}/out/vs/workbench/workbench.web.api.js"
></script>
<script
src=
"
{{VS_BASE}}
/static-{{COMMIT}}/out/vs/loader.js"
></script>
<script
src=
"
{{VS_BASE}}
/static-{{COMMIT}}/out/vs/workbench/workbench.web.api.nls.js"
></script>
<script
src=
"
{{VS_BASE}}
/static-{{COMMIT}}/out/vs/workbench/workbench.web.api.js"
></script>
<!-- TODO@coder: This errors with multiple anonymous define calls (one is
workbench.js and one is semver-umd.js). For now use the same method found in
workbench-dev.html. Appears related to the timing of the script load events. -->
<!-- <script src="
.
/static-{{COMMIT}}/out/vs/workbench/workbench.js"></script> -->
<!-- <script src="
{{VS_BASE}}
/static-{{COMMIT}}/out/vs/workbench/workbench.js"></script> -->
<script>
// NOTE: Changes to inline scripts require update of content security policy
require
([
'
vs/code/browser/workbench/workbench
'
],
function
()
{});
</script>
</html>
src/node/vscode/workbench.html
浏览文件 @
bf1be16d
...
...
@@ -19,9 +19,9 @@
<meta
id=
"vscode-remote-nls-configuration"
data-settings=
"{{NLS_CONFIGURATION}}"
>
<!-- Workbench Icon/Manifest/CSS -->
<link
rel=
"icon"
href=
"
..
/static/src/browser/media/favicon.ico"
type=
"image/x-icon"
/>
<link
rel=
"manifest"
href=
"
..
/static/src/browser/media/manifest.json"
crossorigin=
"use-credentials"
>
<link
rel=
"apple-touch-icon"
href=
"
..
/static/src/browser/media/code-server.png"
/>
<link
rel=
"icon"
href=
"
{{BASE}}
/static/src/browser/media/favicon.ico"
type=
"image/x-icon"
/>
<link
rel=
"manifest"
href=
"
{{BASE}}
/static/src/browser/media/manifest.json"
crossorigin=
"use-credentials"
>
<link
rel=
"apple-touch-icon"
href=
"
{{BASE}}
/static/src/browser/media/code-server.png"
/>
<meta
name=
"apple-mobile-web-app-capable"
content=
"yes"
>
</head>
...
...
@@ -30,11 +30,12 @@
<!-- Startup (do not modify order of script tags!) -->
<script>
const
basePath
=
window
.
location
.
pathname
.
replace
(
/
\/
+$/
,
''
);
const
base
=
window
.
location
.
origin
+
basePath
;
const
parts
=
window
.
location
.
pathname
.
replace
(
/^
\/
/g
,
""
).
split
(
"
/
"
)
parts
[
parts
.
length
-
1
]
=
"
{{VS_BASE}}
"
const
url
=
new
URL
(
window
.
location
.
origin
+
"
/
"
+
parts
.
join
(
"
/
"
))
const
el
=
document
.
getElementById
(
'
vscode-remote-commit
'
);
const
commit
=
el
?
el
.
getAttribute
(
'
data-settings
'
)
:
""
;
const
staticBase
=
base
+
'
/static-
'
+
commit
;
const
staticBase
=
url
.
href
+
'
/static-
'
+
commit
;
self
.
require
=
{
baseUrl
:
`
${
staticBase
}
/out`
,
paths
:
{
...
...
@@ -48,7 +49,7 @@
},
};
</script>
<script
src=
"
.
/static/out/vs/loader.js"
></script>
<script
src=
"
{{VS_BASE}}
/static/out/vs/loader.js"
></script>
<script>
require
([
'
vs/code/browser/workbench/workbench
'
],
function
()
{});
</script>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录