@@ -5,13 +5,9 @@ import http from "http"
55import * as path from "path"
66import { CliMessage , OpenCommandPipeArgs } from "../../lib/vscode/src/vs/server/ipc"
77import { plural } from "../common/util"
8- import { HealthHttpProvider } from "./routes/health"
9- import { LoginHttpProvider } from "./routes/login"
10- import { ProxyHttpProvider } from "./routes/proxy"
11- import { StaticHttpProvider } from "./routes/static"
12- import { UpdateHttpProvider } from "./routes/update"
13- import { VscodeHttpProvider } from "./routes/vscode"
8+ import { createApp , ensureAddress } from "./app"
149import {
10+ AuthType ,
1511 DefaultedArgs ,
1612 optionDescriptions ,
1713 parse ,
@@ -21,9 +17,8 @@ import {
2117 shouldRunVsCodeCli ,
2218} from "./cli"
2319import { coderCloudBind } from "./coder-cloud"
24- import { AuthType , HttpServer , HttpServerOptions } from "./http"
2520import { loadPlugins } from "./plugin"
26- import { hash , humanPath , open } from "./util"
21+ import { humanPath , open } from "./util"
2722import { ipcMain , WrapperProcess } from "./wrapper"
2823
2924let pkg : { version ?: string ; commit ?: string } = { }
@@ -117,65 +112,39 @@ export const openInExistingInstance = async (args: DefaultedArgs, socketPath: st
117112}
118113
119114const main = async ( args : DefaultedArgs ) : Promise < void > => {
115+ logger . info ( `code-server ${ version } ${ commit } ` )
116+
120117 logger . info ( `Using user-data-dir ${ humanPath ( args [ "user-data-dir" ] ) } ` )
121118 logger . trace ( `Using extensions-dir ${ humanPath ( args [ "extensions-dir" ] ) } ` )
122119
123120 if ( args . auth === AuthType . Password && ! args . password ) {
124121 throw new Error ( "Please pass in a password via the config file or $PASSWORD" )
125122 }
126-
127- // Spawn the main HTTP server.
128- const options : HttpServerOptions = {
129- auth : args . auth ,
130- commit,
131- host : args . host ,
132- // The hash does not add any actual security but we do it for obfuscation purposes.
133- password : args . password ? hash ( args . password ) : undefined ,
134- port : args . port ,
135- proxyDomains : args [ "proxy-domain" ] ,
136- socket : args . socket ,
137- cert : args . cert && args . cert . value ,
138- certKey : args [ "cert-key" ] ,
139- }
140-
141- if ( options . cert && ! options . certKey ) {
142- throw new Error ( "--cert-key is missing" )
143- }
144-
145- const httpServer = new HttpServer ( options )
146- httpServer . registerHttpProvider ( [ "/" , "/vscode" ] , VscodeHttpProvider , args )
147- httpServer . registerHttpProvider ( "/update" , UpdateHttpProvider , false )
148- httpServer . registerHttpProvider ( "/proxy" , ProxyHttpProvider )
149- httpServer . registerHttpProvider ( "/login" , LoginHttpProvider , args . config ! , args . usingEnvPassword )
150- httpServer . registerHttpProvider ( "/static" , StaticHttpProvider )
151- httpServer . registerHttpProvider ( "/healthz" , HealthHttpProvider , httpServer . heart )
152-
153- await loadPlugins ( httpServer , args )
154-
155123 ipcMain . onDispose ( ( ) => {
156- httpServer . dispose ( ) . then ( ( errors ) => {
157- errors . forEach ( ( error ) => logger . error ( error . message ) )
158- } )
124+ // TODO: register disposables
159125 } )
160126
161- logger . info ( `code-server ${ version } ${ commit } ` )
162- logger . info ( `Using config file ${ humanPath ( args . config ) } ` )
127+ const [ app , server ] = await createApp ( args )
128+ const serverAddress = ensureAddress ( server )
129+
130+ // TODO: register routes
131+ await loadPlugins ( app , args )
163132
164- const serverAddress = await httpServer . listen ( )
133+ logger . info ( `Using config file ${ humanPath ( args . config ) } ` )
165134 logger . info ( `HTTP server listening on ${ serverAddress } ${ args . link ? "(randomized by --link)" : "" } ` )
166135
167136 if ( args . auth === AuthType . Password ) {
137+ logger . info ( " - Authentication is enabled" )
168138 if ( args . usingEnvPassword ) {
169139 logger . info ( " - Using password from $PASSWORD" )
170140 } else {
171141 logger . info ( ` - Using password from ${ humanPath ( args . config ) } ` )
172142 }
173- logger . info ( " - To disable use `--auth none`" )
174143 } else {
175- logger . info ( ` - No authentication ${ args . link ? "(disabled by --link)" : "" } ` )
144+ logger . info ( ` - Authentication is disabled ${ args . link ? "(disabled by --link)" : "" } ` )
176145 }
177146
178- if ( httpServer . protocol === "https" ) {
147+ if ( args . cert ) {
179148 logger . info (
180149 args . cert && args . cert . value
181150 ? ` - Using provided certificate and key for HTTPS`
@@ -192,15 +161,15 @@ const main = async (args: DefaultedArgs): Promise<void> => {
192161
193162 if ( args . link ) {
194163 try {
195- await coderCloudBind ( serverAddress ! , args . link . value )
164+ await coderCloudBind ( serverAddress , args . link . value )
196165 logger . info ( " - Connected to cloud agent" )
197166 } catch ( err ) {
198167 logger . error ( err . message )
199168 ipcMain . exit ( 1 )
200169 }
201170 }
202171
203- if ( serverAddress && ! options . socket && args . open ) {
172+ if ( serverAddress && ! args . socket && args . open ) {
204173 // The web socket doesn't seem to work if browsing with 0.0.0.0.
205174 const openAddress = serverAddress . replace ( / : \/ \/ 0 .0 .0 .0 / , "://localhost" )
206175 await open ( openAddress ) . catch ( ( error : Error ) => {
0 commit comments