Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
彭彦祖
code-server
提交
be3f0c43
C
code-server
项目概览
彭彦祖
/
code-server
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
1
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,发现更多精彩内容 >>
未验证
提交
be3f0c43
编写于
2月 26, 2019
作者:
K
Kyle Carberry
提交者:
GitHub
2月 26, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes browser app, adds no-auth (#38)
* Add no-auth flag * Install packages for app dir
上级
a07d0c9c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
79 addition
and
40 deletion
+79
-40
packages/server/src/cli.ts
packages/server/src/cli.ts
+45
-34
packages/server/src/server.ts
packages/server/src/server.ts
+33
-6
scripts/install-packages.ts
scripts/install-packages.ts
+1
-0
未找到文件。
packages/server/src/cli.ts
浏览文件 @
be3f0c43
...
...
@@ -24,6 +24,7 @@ export class Entry extends Command {
open
:
flags
.
boolean
({
char
:
"
o
"
,
description
:
"
Open in browser on startup
"
}),
port
:
flags
.
integer
({
char
:
"
p
"
,
default
:
8080
,
description
:
"
Port to bind on
"
}),
version
:
flags
.
version
({
char
:
"
v
"
}),
"
no-auth
"
:
flags
.
boolean
({
default
:
false
}),
// Dev flags
"
bootstrap-fork
"
:
flags
.
string
({
hidden
:
true
}),
...
...
@@ -132,41 +133,47 @@ export class Entry extends Command {
const
password
=
"
023450wf0951
"
;
const
hasCustomHttps
=
certData
&&
certKeyData
;
const
app
=
await
createApp
((
app
)
=>
{
app
.
use
((
req
,
res
,
next
)
=>
{
res
.
on
(
"
finish
"
,
()
=>
{
logger
.
trace
(
`\u001B[1m
${
req
.
method
}
${
res
.
statusCode
}
\u001B[0m
${
req
.
url
}
`
,
field
(
"
host
"
,
req
.
hostname
),
field
(
"
ip
"
,
req
.
ip
));
const
app
=
await
createApp
({
bypassAuth
:
flags
[
"
no-auth
"
],
registerMiddleware
:
(
app
):
void
=>
{
app
.
use
((
req
,
res
,
next
)
=>
{
res
.
on
(
"
finish
"
,
()
=>
{
logger
.
trace
(
`\u001B[1m
${
req
.
method
}
${
res
.
statusCode
}
\u001B[0m
${
req
.
url
}
`
,
field
(
"
host
"
,
req
.
hostname
),
field
(
"
ip
"
,
req
.
ip
));
});
next
();
});
next
();
});
// If we're not running from the binary and we aren't serving the static
// pre-built version, use webpack to serve the web files.
if
(
!
isCli
&&
!
serveStatic
)
{
const
webpackConfig
=
require
(
path
.
join
(
__dirname
,
"
..
"
,
"
..
"
,
"
web
"
,
"
webpack.config.js
"
));
const
compiler
=
require
(
"
webpack
"
)(
webpackConfig
);
app
.
use
(
require
(
"
webpack-dev-middleware
"
)(
compiler
,
{
logger
,
publicPath
:
webpackConfig
.
output
.
publicPath
,
stats
:
webpackConfig
.
stats
,
}));
app
.
use
(
require
(
"
webpack-hot-middleware
"
)(
compiler
));
}
},
{
builtInExtensionsDirectory
:
builtInExtensionsDir
,
dataDirectory
:
dataDir
,
workingDirectory
:
workingDir
,
fork
:
(
modulePath
:
string
,
args
:
string
[],
options
:
ForkOptions
):
ChildProcess
=>
{
if
(
options
&&
options
.
env
&&
options
.
env
.
AMD_ENTRYPOINT
)
{
return
forkModule
(
options
.
env
.
AMD_ENTRYPOINT
,
args
,
options
,
dataDir
);
// If we're not running from the binary and we aren't serving the static
// pre-built version, use webpack to serve the web files.
if
(
!
isCli
&&
!
serveStatic
)
{
const
webpackConfig
=
require
(
path
.
join
(
__dirname
,
"
..
"
,
"
..
"
,
"
web
"
,
"
webpack.config.js
"
));
const
compiler
=
require
(
"
webpack
"
)(
webpackConfig
);
app
.
use
(
require
(
"
webpack-dev-middleware
"
)(
compiler
,
{
logger
,
publicPath
:
webpackConfig
.
output
.
publicPath
,
stats
:
webpackConfig
.
stats
,
}));
app
.
use
(
require
(
"
webpack-hot-middleware
"
)(
compiler
));
}
return
fork
(
modulePath
,
args
,
options
);
},
},
password
,
hasCustomHttps
?
{
key
:
certKeyData
,
cert
:
certData
,
}
:
undefined
);
serverOptions
:
{
builtInExtensionsDirectory
:
builtInExtensionsDir
,
dataDirectory
:
dataDir
,
workingDirectory
:
workingDir
,
fork
:
(
modulePath
:
string
,
args
:
string
[],
options
:
ForkOptions
):
ChildProcess
=>
{
if
(
options
&&
options
.
env
&&
options
.
env
.
AMD_ENTRYPOINT
)
{
return
forkModule
(
options
.
env
.
AMD_ENTRYPOINT
,
args
,
options
,
dataDir
);
}
return
fork
(
modulePath
,
args
,
options
);
},
},
password
,
httpsOptions
:
hasCustomHttps
?
{
key
:
certKeyData
,
cert
:
certData
,
}
:
undefined
,
});
logger
.
info
(
"
Starting webserver...
"
,
field
(
"
host
"
,
flags
.
host
),
field
(
"
port
"
,
flags
.
port
));
app
.
server
.
listen
(
flags
.
port
,
flags
.
host
);
...
...
@@ -191,8 +198,12 @@ export class Entry extends Command {
logger
.
warn
(
"
Documentation on securing your setup: https://coder.com/docs
"
);
}
logger
.
info
(
"
"
);
logger
.
info
(
`Password:\u001B[1m
${
password
}
`
);
if
(
!
flags
[
"
no-auth
"
])
{
logger
.
info
(
"
"
);
logger
.
info
(
`Password:\u001B[1m
${
password
}
`
);
}
else
{
logger
.
warn
(
"
Launched without authentication.
"
);
}
logger
.
info
(
"
"
);
logger
.
info
(
"
Started (click the link below to open):
"
);
logger
.
info
(
`http://localhost:
${
flags
.
port
}
/`
);
...
...
packages/server/src/server.ts
浏览文件 @
be3f0c43
...
...
@@ -20,7 +20,15 @@ import { handle as handleTunnel } from "@coder/tunnel/src/server";
import
{
createPortScanner
}
from
"
./portScanner
"
;
import
{
buildDir
,
isCli
}
from
"
./constants
"
;
export
const
createApp
=
async
(
registerMiddleware
?:
(
app
:
express
.
Application
)
=>
void
,
options
?:
ServerOptions
,
password
?:
string
,
httpsOptions
?:
https
.
ServerOptions
):
Promise
<
{
interface
CreateAppOptions
{
registerMiddleware
?:
(
app
:
express
.
Application
)
=>
void
;
serverOptions
?:
ServerOptions
;
password
?:
string
;
httpsOptions
?:
https
.
ServerOptions
;
bypassAuth
?:
boolean
;
}
export
const
createApp
=
async
(
options
:
CreateAppOptions
):
Promise
<
{
readonly
express
:
express
.
Application
;
readonly
server
:
http
.
Server
;
readonly
wss
:
ws
.
Server
;
...
...
@@ -38,15 +46,26 @@ export const createApp = async (registerMiddleware?: (app: express.Application)
return
cookies
;
};
const
ensureAuthed
=
(
req
:
http
.
IncomingMessage
,
res
:
express
.
Response
):
boolean
=>
{
if
(
!
isAuthed
(
req
))
{
res
.
status
(
401
);
res
.
end
();
return
false
;
}
return
true
;
};
const
isAuthed
=
(
req
:
http
.
IncomingMessage
):
boolean
=>
{
try
{
if
(
!
password
||
!
isCli
)
{
if
(
!
options
.
password
||
options
.
bypassAuth
)
{
return
true
;
}
// Try/catch placed here just in case
const
cookies
=
parseCookies
(
req
);
if
(
cookies
.
password
&&
cookies
.
password
===
password
)
{
if
(
cookies
.
password
&&
cookies
.
password
===
options
.
password
)
{
return
true
;
}
}
catch
(
ex
)
{
...
...
@@ -62,8 +81,8 @@ export const createApp = async (registerMiddleware?: (app: express.Application)
};
const
app
=
express
();
if
(
registerMiddleware
)
{
registerMiddleware
(
app
);
if
(
options
.
registerMiddleware
)
{
options
.
registerMiddleware
(
app
);
}
const
certs
=
await
new
Promise
<
pem
.
CertificateCreationResult
>
((
res
,
rej
):
void
=>
{
...
...
@@ -134,7 +153,7 @@ export const createApp = async (registerMiddleware?: (app: express.Application)
onClose
:
(
cb
):
void
=>
ws
.
addEventListener
(
"
close
"
,
()
=>
cb
()),
};
const
server
=
new
Server
(
connection
,
options
);
const
server
=
new
Server
(
connection
,
options
.
serverOptions
);
});
const
baseDir
=
buildDir
||
path
.
join
(
__dirname
,
"
..
"
);
...
...
@@ -150,6 +169,10 @@ export const createApp = async (registerMiddleware?: (app: express.Application)
}
});
app
.
get
(
"
/resource/:url(*)
"
,
async
(
req
,
res
)
=>
{
if
(
!
ensureAuthed
(
req
,
res
))
{
return
;
}
try
{
const
fullPath
=
`/
${
req
.
params
.
url
}
`
;
// const relative = path.relative(options!.dataDirectory, fullPath);
...
...
@@ -184,6 +207,10 @@ export const createApp = async (registerMiddleware?: (app: express.Application)
}
});
app
.
post
(
"
/resource/:url(*)
"
,
async
(
req
,
res
)
=>
{
if
(
!
ensureAuthed
(
req
,
res
))
{
return
;
}
try
{
const
fullPath
=
`/
${
req
.
params
.
url
}
`
;
...
...
scripts/install-packages.ts
浏览文件 @
be3f0c43
...
...
@@ -40,3 +40,4 @@ const handlePackages = (dir: string): void => {
};
handlePackages
(
resolve
(
__dirname
,
"
..
"
,
"
packages
"
));
handlePackages
(
resolve
(
__dirname
,
"
..
"
,
"
packages
"
,
"
app
"
));
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录