Archived
1
0

Use upstream server (#4414)

* Flesh out fixes to align with upstream.

* Update route handlers to better reflect fallback behavior.

* Add platform to vscode-reh-web task

Our strategy has been to build once and then recompile native modules
for individual platforms.  It looks like VS Code builds from scratch for
each platform.

But we can target any platform, grab the pre-packaged folder, then
continue with own packaging.

In the future we may want to rework to match upstream.

* Fix issue where workspace args are not parsed.

* Fix issues surrounding opening files within code-server's terminal.

* Readd parent wrapper for hot reload.

* Allow more errors.

* Fix issues surrounding Coder link.

* Add dir creation and fix cli

It seems VS Code explodes when certain directories do not exist so
import the reh agent instead of the server component since it creates
the directories (require patching thus the VS Code update).

Also the CLI (for installing extensions) did not seem to be working so
point that to the same place since it also exports a function for
running that part of the CLI.

* Remove hardcoded VSCODE_DEV=1

This causes VS Code to use the development HTML file.  Move this to the
watch command instead.

I deleted the other stuff before it as well since in the latest main.js
they do not have this code so I figure we should be safe to omit it.

* Fix mismatching commit between client and server

* Mostly restore command-line parity

Restore most everything and remove the added server arguments.  This
will let us add and remove options after later so we can contain the
number of breaking changes.

To accomplish this a hard separation is added between the CLI arguments
and the server arguments.

The separation between user-provided arguments and arguments with
defaults is also made more clear.

The extra directory flags have been left out as they were buggy and
should be implemented upstream although I think there are better
solutions anyway.  locale and install-source are unsupported with the
web remote and are left removed.  It is unclear whether they were used
before anyway.

Some restored flags still need to have their behavior re-implemented.

* Fix static endpoint not emitting 404s

This fixes the last failing unit test.

Fix a missing dependency, add some generic reverse proxy support for the
protocol, and add back a missing nfpm fix.

* Import missing logError

* Fix 403 errors

* Add code-server version to about dialog

* Use user settings to disable welcome page

The workspace setting seems to be recognized but if so it is having no
effect.

* Update VS Code cache step with new build directories

Co-authored-by: Asher <ash@coder.com>
This commit is contained in:
Teffen
2021-11-10 00:28:31 -05:00
committed by GitHub
parent 31d5823d10
commit 1b60ef418c
18 changed files with 285 additions and 275 deletions

View File

@ -8,7 +8,7 @@ import { rootPath } from "../constants"
import { replaceTemplates } from "../http"
import { escapeHtml, getMediaMime } from "../util"
const notFoundCodes = ["ENOENT", "EISDIR", "FileNotFound"]
const notFoundCodes = ["ENOENT", "EISDIR"]
export const errorHandler: express.ErrorRequestHandler = async (err, req, res, next) => {
if (notFoundCodes.includes(err.code)) {
err.status = HttpCode.NotFound

View File

@ -121,6 +121,7 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
"/_static",
express.static(rootPath, {
cacheControl: commit !== "development",
fallthrough: false,
}),
)

View File

@ -1,7 +1,5 @@
import * as express from "express"
import path from "path"
import { AuthType, DefaultedArgs } from "../cli"
import { version as codeServerVersion, vsRootPath } from "../constants"
import { DefaultedArgs } from "../cli"
import { ensureAuthenticated, authenticated, redirect } from "../http"
import { loadAMDModule } from "../util"
import { Router as WsRouter, WebsocketRouter } from "../wsRouter"
@ -10,47 +8,23 @@ import { errorHandler } from "./errors"
export interface VSServerResult {
router: express.Router
wsRouter: WebsocketRouter
codeServerMain: CodeServerLib.IServerProcessMain
codeServerMain: CodeServerLib.IServerAPI
}
export const createVSServerRouter = async (args: DefaultedArgs): Promise<VSServerResult> => {
// Delete `VSCODE_CWD` very early even before
// importing bootstrap files. We have seen
// reports where `code .` would use the wrong
// current working directory due to our variable
// somehow escaping to the parent shell
// (https://github.com/microsoft/vscode/issues/126399)
delete process.env["VSCODE_CWD"]
// See ../../../vendor/modules/code-oss-dev/src/vs/server/main.js.
const createVSServer = await loadAMDModule<CodeServerLib.CreateServer>(
"vs/server/remoteExtensionHostAgent",
"createServer",
)
const bootstrap = require(path.join(vsRootPath, "out", "bootstrap"))
const bootstrapNode = require(path.join(vsRootPath, "out", "bootstrap-node"))
const product = require(path.join(vsRootPath, "product.json"))
// Avoid Monkey Patches from Application Insights
bootstrap.avoidMonkeyPatchFromAppInsights()
// Enable portable support
bootstrapNode.configurePortable(product)
// Enable ASAR support
bootstrap.enableASARSupport()
// Signal processes that we got launched as CLI
process.env["VSCODE_CLI"] = "1"
const createVSServer = await loadAMDModule<CodeServerLib.CreateVSServer>("vs/server/entry", "createVSServer")
const serverUrl = new URL(`${args.cert ? "https" : "http"}://${args.host}:${args.port}`)
const codeServerMain = await createVSServer({
codeServerVersion,
serverUrl,
args,
authed: args.auth !== AuthType.None,
disableUpdateCheck: !!args["disable-update-check"],
const codeServerMain = await createVSServer(null, {
connectionToken: "0000",
...args,
// For some reason VS Code takes the port as a string.
port: typeof args.port !== "undefined" ? args.port.toString() : undefined,
})
const netServer = await codeServerMain.startup({ listenWhenReady: false })
const router = express.Router()
const wsRouter = WsRouter()
@ -66,13 +40,19 @@ export const createVSServerRouter = async (args: DefaultedArgs): Promise<VSServe
})
router.all("*", ensureAuthenticated, (req, res, next) => {
req.on("error", (error) => errorHandler(error, req, res, next))
req.on("error", (error: any) => {
if (error instanceof Error && ["EntryNotFound", "FileNotFound", "HttpError"].includes(error.message)) {
next()
}
netServer.emit("request", req, res)
errorHandler(error, req, res, next)
})
codeServerMain.handleRequest(req, res)
})
wsRouter.ws("/", ensureAuthenticated, (req) => {
netServer.emit("upgrade", req, req.socket, req.head)
codeServerMain.handleUpgrade(req, req.socket)
req.socket.resume()
})