mirror of
https://github.com/coder/code-server.git
synced 2024-11-27 18:14:04 +03:00
Fixes for @ammarb
This commit is contained in:
parent
6e8248cf0c
commit
c3c24fe4d2
@ -48,7 +48,7 @@ export interface Args extends VsArgs {
|
|||||||
readonly "reuse-window"?: boolean
|
readonly "reuse-window"?: boolean
|
||||||
readonly "new-window"?: boolean
|
readonly "new-window"?: boolean
|
||||||
|
|
||||||
readonly "coder-link"?: OptionalString
|
readonly "coder-bind"?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Option<T> {
|
interface Option<T> {
|
||||||
@ -159,10 +159,10 @@ const options: Options<Required<Args>> = {
|
|||||||
log: { type: LogLevel },
|
log: { type: LogLevel },
|
||||||
verbose: { type: "boolean", short: "vvv", description: "Enable verbose logging." },
|
verbose: { type: "boolean", short: "vvv", description: "Enable verbose logging." },
|
||||||
|
|
||||||
"coder-link": {
|
"coder-bind": {
|
||||||
type: OptionalString,
|
type: "string",
|
||||||
description: `
|
description: `
|
||||||
Securely link code-server via Coder Cloud with the passed name. You'll get a URL like
|
Securely bind code-server via Coder Cloud with the passed name. You'll get a URL like
|
||||||
https://myname.coder-cloud.com at which you can easily access your code-server instance.
|
https://myname.coder-cloud.com at which you can easily access your code-server instance.
|
||||||
Authorization is done via GitHub. Only the first code-server spawned with the current
|
Authorization is done via GitHub. Only the first code-server spawned with the current
|
||||||
configuration will be accessible.`,
|
configuration will be accessible.`,
|
||||||
|
@ -9,7 +9,7 @@ import xdgBasedir from "xdg-basedir"
|
|||||||
|
|
||||||
const coderCloudAgent = path.resolve(__dirname, "../../lib/coder-cloud-agent")
|
const coderCloudAgent = path.resolve(__dirname, "../../lib/coder-cloud-agent")
|
||||||
|
|
||||||
export async function coderCloudLink(serverName: string): Promise<void> {
|
export async function coderCloudBind(serverName: string): Promise<void> {
|
||||||
const agent = spawn(coderCloudAgent, ["link", serverName], {
|
const agent = spawn(coderCloudAgent, ["link", serverName], {
|
||||||
stdio: ["inherit", "inherit", "pipe"],
|
stdio: ["inherit", "inherit", "pipe"],
|
||||||
})
|
})
|
||||||
|
@ -12,7 +12,7 @@ import { StaticHttpProvider } from "./app/static"
|
|||||||
import { UpdateHttpProvider } from "./app/update"
|
import { UpdateHttpProvider } from "./app/update"
|
||||||
import { VscodeHttpProvider } from "./app/vscode"
|
import { VscodeHttpProvider } from "./app/vscode"
|
||||||
import { Args, bindAddrFromAllSources, optionDescriptions, parse, readConfigFile, setDefaults } from "./cli"
|
import { Args, bindAddrFromAllSources, optionDescriptions, parse, readConfigFile, setDefaults } from "./cli"
|
||||||
import { coderCloudLink, coderCloudProxy } from "./coder-cloud"
|
import { coderCloudBind, coderCloudProxy } from "./coder-cloud"
|
||||||
import { AuthType, HttpServer, HttpServerOptions } from "./http"
|
import { AuthType, HttpServer, HttpServerOptions } from "./http"
|
||||||
import { loadPlugins } from "./plugin"
|
import { loadPlugins } from "./plugin"
|
||||||
import { generateCertificate, hash, humanPath, open } from "./util"
|
import { generateCertificate, hash, humanPath, open } from "./util"
|
||||||
@ -36,13 +36,15 @@ const version = pkg.version || "development"
|
|||||||
const commit = pkg.commit || "development"
|
const commit = pkg.commit || "development"
|
||||||
|
|
||||||
const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise<void> => {
|
const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise<void> => {
|
||||||
if (args["coder-link"]) {
|
if (args["coder-bind"]) {
|
||||||
// If we're being exposed to the cloud, we listen on a random address.
|
// If we're being exposed to the cloud, we listen on a random address and disable auth.
|
||||||
args = {
|
args = {
|
||||||
...args,
|
...args,
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
port: 0,
|
port: 0,
|
||||||
|
auth: AuthType.None,
|
||||||
}
|
}
|
||||||
|
logger.info("coder-bind: disabling auth and listening on random localhost port")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!args.auth) {
|
if (!args.auth) {
|
||||||
@ -132,8 +134,6 @@ const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise<void>
|
|||||||
httpServer.proxyDomains.forEach((domain) => logger.info(` - *.${domain}`))
|
httpServer.proxyDomains.forEach((domain) => logger.info(` - *.${domain}`))
|
||||||
}
|
}
|
||||||
|
|
||||||
coderCloudProxy(serverAddress!)
|
|
||||||
|
|
||||||
if (serverAddress && !options.socket && args.open) {
|
if (serverAddress && !options.socket && args.open) {
|
||||||
// The web socket doesn't seem to work if browsing with 0.0.0.0.
|
// The web socket doesn't seem to work if browsing with 0.0.0.0.
|
||||||
const openAddress = serverAddress.replace(/:\/\/0.0.0.0/, "://localhost")
|
const openAddress = serverAddress.replace(/:\/\/0.0.0.0/, "://localhost")
|
||||||
@ -141,16 +141,12 @@ const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise<void>
|
|||||||
logger.info(`Opened ${openAddress}`)
|
logger.info(`Opened ${openAddress}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args["coder-link"]) {
|
if (args["coder-bind"]) {
|
||||||
if (!args["coder-link"].value) {
|
logger.info(`linking code-server to the cloud with name ${args["coder-bind"]}`)
|
||||||
logger.error("You must pass a name to link with coder cloud. See --help")
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info(`linking code-server to the cloud with name ${args["coder-link"].value}`)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await coderCloudLink(args["coder-link"].value)
|
await coderCloudBind(args["coder-bind"])
|
||||||
|
coderCloudProxy(serverAddress!)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err.message)
|
logger.error(err.message)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user