30 Commits

Author SHA1 Message Date
1134780b8b refactor: make wsProxy async 2021-06-08 14:33:14 -07:00
49c26f70f7 Add logout route 2021-05-04 13:29:39 -05:00
f0bafa387f Move connection logic into connection class
- Moved everything I could into the class itself.
- Improve the logging situation a bit.
- Switch some trace logs to debug.
- Get debug port from message arguments.
2021-04-21 11:48:45 -05:00
619934dc29 Authenticate plugin routes (#2720) 2021-02-12 14:56:39 -06:00
e4e0ac43b0 Don't load plugins in tests
This can affect the test behavior and results.
2021-02-09 15:39:57 -06:00
3226d50747 Rename papi to pluginApi 2021-02-09 13:09:40 -06:00
2fe3d57df3 Mount plugins before bodyParser
Otherwise it consumes the body and plugins won't be able to do things
like proxy POST requests.
2021-02-09 13:09:39 -06:00
36aad9bdab Move global express args definition
This way tests that import the http utilities but not the routes won't
error due to missing types.
2021-02-09 13:09:36 -06:00
b13db3124b Add health websocket
This is used by some of our services.
2021-02-09 13:09:33 -06:00
00cfd9bdf1 Add working directory to plugin config 2021-02-09 13:09:31 -06:00
017b1cc633 Add deinit for plugins 2021-02-09 13:09:29 -06:00
055e0ef9ec Provide WsRouter to plugins 2021-02-09 13:09:27 -06:00
c08e3bb06d Add /absproxy to remove --proxy-path-passthrough
See https://github.com/cdr/code-server/issues/2222#issuecomment-765235938

Makes way more sense.
2021-02-05 11:44:34 -05:00
58d72d53a1 routes/index.ts: register proxy routes before body-parser
Any json or urlencoded request bodies were being consumed by body-parser
before they could be proxied. That's why requests without Content-Type
were proxied correctly as body-parser would not consume their body.

This allows the http-proxy package to passthrough the request body correctly
in all instances.

Closes #2377
2021-02-01 11:08:40 -05:00
c32d8b155f heart.ts: Fix leak when server closes
This had me very confused for quite a while until I did a binary search
inspection on route/index.ts. Only with the heart.beat line commented
out did my tests pass without leaking.

They weren't leaking fds but just this heartbeat timer and node of
course prints just fds that are active when it detects some sort of leak
I guess and that made the whole thing very confusing. These fds are not
leaked and will close when node's event loop detects there are no more
callbacks to run.

no of handles 3

tcp stream {
  fd: 20,
  readable: false,
  writable: true,
  address: {},
  serverAddr: null
}

tcp stream {
  fd: 22,
  readable: false,
  writable: true,
  address: {},
  serverAddr: null
}

tcp stream {
  fd: 23,
  readable: true,
  writable: false,
  address: {},
  serverAddr: null
}

It kept printing the above text again and again for 60s and then the
test binary times out I think. I'm not sure if it was node printing the
stuff above or if it was a mocha thing. But it was really confusing...

cc @code-asher for thoughts on what was going on.

edit: It was the leaked-handles import in socket.test.ts!!!
Not sure if we should keep it, this was really confusing and misleading.
2021-01-20 02:06:44 -05:00
ba4a24809c routes/index.ts: Correctly register wsErrorHandler
express requires all 4 arguments to be declared for a error handler.
It's very unfortunate that our types do not handle this.
2021-01-20 02:06:43 -05:00
244afa402e routes: Redirect from /login when auth is disabled (#2456)
Sometimes I start with auth but then disable. Now I can just reload the
login page in my browser to be greeted with code-server.
2020-12-14 12:33:36 -05:00
2a3608df53 Skip heartbeat on /healthz endpoint (#2333)
I managed to lose this in the rewrite.

Fixes #2327.
2020-11-18 12:19:08 -06:00
40a7c11ce3 node/routes: Fix error handling
We should always send HTML if the user agent expects it.

If they do not, they should clearly indicate such via the Accept header.

Closes #2297
2020-11-13 18:44:28 -05:00
b8340a2ae9 Close sockets correctly 2020-11-10 17:55:04 -06:00
fe399ff0fe Fix formatting 2020-11-06 14:47:08 -05:00
706bc23f04 plugin: Fixes for CI 2020-11-06 10:13:01 -05:00
e03bbe3149 routes/apps.ts: Implement /api/applications endpoint 2020-11-06 10:12:46 -05:00
e08a55d44a src/node/plugin.ts: Implement new plugin API 2020-11-06 10:12:45 -05:00
f7076247f9 Move domain proxy to routes
This matches better with the other routes.

Also add a missing authentication check to the path proxy web socket.
2020-11-05 17:07:32 -06:00
cb991a9143 Handle errors for JSON requests
Previously it would have just given them the error HTML.
2020-11-05 15:19:56 -06:00
7b2752a62c Move websocket routes into a separate app
This is mostly so we don't have to do any wacky patching but it also
makes it so we don't have to keep checking if the request is a web
socket request every time we add middleware.
2020-11-05 15:08:09 -06:00
9e09c1f92b Upgrade to Express 5
Now async routes are handled!
2020-11-05 15:08:08 -06:00
6ab6cb4f07 Fix error handler types 2020-10-27 17:20:13 -05:00
112eda4605 Convert routes to Express 2020-10-26 17:56:13 -05:00