Skip to content

Commit 6d45c79

Browse files
Merge branch 'coder:main' into main
2 parents 0552d23 + fb2afbd commit 6d45c79

File tree

13 files changed

+241
-243
lines changed

13 files changed

+241
-243
lines changed

ci/build/npm-postinstall.sh

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ symlink_bin_script() {
5151
cd "$oldpwd"
5252
}
5353

54+
command_exists() {
55+
if [ ! "$1" ]; then return 1; fi
56+
command -v "$@" > /dev/null
57+
}
58+
59+
is_root() {
60+
if command_exists id && [ "$(id -u)" = 0 ]; then
61+
return 0
62+
fi
63+
return 1
64+
}
65+
5466
OS="$(os)"
5567

5668
main() {
@@ -75,17 +87,20 @@ main() {
7587
exit 1
7688
fi
7789

78-
case "${npm_config_user_agent-}" in npm*)
79-
# We are running under npm.
80-
if [ "${npm_config_unsafe_perm-}" != "true" ]; then
81-
echo "Please pass --unsafe-perm to npm to install code-server"
82-
echo "Otherwise the postinstall script does not have permissions to run"
83-
echo "See https://docs.npmjs.com/misc/config#unsafe-perm"
84-
echo "See https://stackoverflow.com/questions/49084929/npm-sudo-global-installation-unsafe-perm"
85-
exit 1
86-
fi
87-
;;
88-
esac
90+
# Under npm, if we are running as root, we need --unsafe-perm otherwise
91+
# post-install scripts will not have sufficient permissions to do their thing.
92+
if is_root; then
93+
case "${npm_config_user_agent-}" in npm*)
94+
if [ "${npm_config_unsafe_perm-}" != "true" ]; then
95+
echo "Please pass --unsafe-perm to npm to install code-server"
96+
echo "Otherwise post-install scripts will not have permissions to run"
97+
echo "See https://docs.npmjs.com/misc/config#unsafe-perm"
98+
echo "See https://stackoverflow.com/questions/49084929/npm-sudo-global-installation-unsafe-perm"
99+
exit 1
100+
fi
101+
;;
102+
esac
103+
fi
89104

90105
if ! vscode_install; then
91106
echo "You may not have the required dependencies to build the native modules."

docs/android.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ nvm install 18
1818
nvm use 18
1919
```
2020

21-
8. Install code-server globally on device with: `npm install --global code-server --unsafe-perm`
21+
8. Install code-server globally on device with: `npm install --global code-server`
2222
9. Run code-server with `code-server`
2323
10. Access on localhost:8080 in your browser
2424

docs/npm.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Installing code-server requires all of the [prerequisites for VS Code developmen
9292
Next, install code-server with:
9393

9494
```bash
95-
npm install --global code-server --unsafe-perm
95+
npm install --global code-server
9696
code-server
9797
# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml
9898
```
@@ -112,7 +112,7 @@ For help and additional troubleshooting, see [#1397](https://github.com/coder/co
112112
After adding the dependencies for your OS, install the code-server package globally:
113113

114114
```bash
115-
npm install --global code-server --unsafe-perm
115+
npm install --global code-server
116116
code-server
117117
# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml
118118
```
@@ -144,8 +144,8 @@ To debug installation issues, install with `npm`:
144144

145145
```shell
146146
# Uninstall
147-
npm uninstall --global --unsafe-perm code-server > /dev/null 2>&1
147+
npm uninstall --global code-server > /dev/null 2>&1
148148

149149
# Install with logging
150-
npm install --loglevel verbose --global --unsafe-perm code-server
150+
npm install --loglevel verbose --global code-server
151151
```

docs/termux.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ code-server --auth none
7070
7. If already installed then use the following command for upgradation.
7171

7272
```
73-
npm update --global code-server --unsafe-perm
73+
npm update --global code-server
7474
```
7575

7676
## Upgrade

src/node/http.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ export const getCookieOptions = (req: express.Request): express.CookieOptions =>
319319
// URL of that page) and the relative path to the root as given to it by the
320320
// backend. Using these two we can determine the true absolute root.
321321
const url = new URL(
322-
req.query.base || req.body.base || "/",
323-
req.query.href || req.body.href || "http://" + (req.headers.host || "localhost"),
322+
req.query.base || req.body?.base || "/",
323+
req.query.href || req.body?.href || "http://" + (req.headers.host || "localhost"),
324324
)
325325
return {
326326
domain: getCookieDomain(url.host, req.args["proxy-domain"]),

src/node/routes/domainProxy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const maybeProxy = (req: Request): string | undefined => {
5353
return undefined
5454
}
5555

56-
router.all("*", async (req, res, next) => {
56+
router.all(/.*/, async (req, res, next) => {
5757
const port = maybeProxy(req)
5858
if (!port) {
5959
return next()
@@ -97,7 +97,7 @@ router.all("*", async (req, res, next) => {
9797

9898
export const wsRouter = WsRouter()
9999

100-
wsRouter.ws("*", async (req, _, next) => {
100+
wsRouter.ws(/.*/, async (req, _, next) => {
101101
const port = maybeProxy(req)
102102
if (!port) {
103103
return next()

src/node/routes/index.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import * as login from "./login"
2525
import * as logout from "./logout"
2626
import * as pathProxy from "./pathProxy"
2727
import * as update from "./update"
28-
import { CodeServerRouteWrapper } from "./vscode"
28+
import * as vscode from "./vscode"
2929

3030
/**
3131
* Register all routes and middleware.
@@ -109,21 +109,21 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
109109
app.router.use("/", domainProxy.router)
110110
app.wsRouter.use("/", domainProxy.wsRouter.router)
111111

112-
app.router.all("/proxy/(:port)(/*)?", async (req, res) => {
112+
app.router.all("/proxy/:port/:path(.*)?", async (req, res) => {
113113
await pathProxy.proxy(req, res)
114114
})
115-
app.wsRouter.get("/proxy/(:port)(/*)?", async (req) => {
115+
app.wsRouter.get("/proxy/:port/:path(.*)?", async (req) => {
116116
await pathProxy.wsProxy(req as pluginapi.WebsocketRequest)
117117
})
118118
// These two routes pass through the path directly.
119119
// So the proxied app must be aware it is running
120120
// under /absproxy/<someport>/
121-
app.router.all("/absproxy/(:port)(/*)?", async (req, res) => {
121+
app.router.all("/absproxy/:port/:path(.*)?", async (req, res) => {
122122
await pathProxy.proxy(req, res, {
123123
passthroughPath: true,
124124
})
125125
})
126-
app.wsRouter.get("/absproxy/(:port)(/*)?", async (req) => {
126+
app.wsRouter.get("/absproxy/:port/:path(.*)?", async (req) => {
127127
await pathProxy.wsProxy(req as pluginapi.WebsocketRequest, {
128128
passthroughPath: true,
129129
})
@@ -170,12 +170,10 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
170170

171171
app.router.use("/update", update.router)
172172

173-
const vsServerRouteHandler = new CodeServerRouteWrapper()
174-
175173
// Note that the root route is replaced in Coder Enterprise by the plugin API.
176174
for (const routePrefix of ["/vscode", "/"]) {
177-
app.router.use(routePrefix, vsServerRouteHandler.router)
178-
app.wsRouter.use(routePrefix, vsServerRouteHandler.wsRouter)
175+
app.router.use(routePrefix, vscode.router)
176+
app.wsRouter.use(routePrefix, vscode.wsRouter.router)
179177
}
180178

181179
app.router.use(() => {
@@ -188,6 +186,6 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
188186
return () => {
189187
heart.dispose()
190188
pluginApi?.dispose()
191-
vsServerRouteHandler.dispose()
189+
vscode.dispose()
192190
}
193191
}

src/node/routes/login.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ router.get("/", async (req, res) => {
6868
res.send(await getRoot(req))
6969
})
7070

71-
router.post<{}, string, { password: string; base?: string }, { to?: string }>("/", async (req, res) => {
72-
const password = sanitizeString(req.body.password)
71+
router.post<{}, string, { password?: string; base?: string } | undefined, { to?: string }>("/", async (req, res) => {
72+
const password = sanitizeString(req.body?.password)
7373
const hashedPasswordFromArgs = req.args["hashed-password"]
7474

7575
try {

src/node/routes/pathProxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function proxy(
2222

2323
if (!(await authenticated(req))) {
2424
// If visiting the root (/:port only) redirect to the login page.
25-
if (!req.params[0] || req.params[0] === "/") {
25+
if (!req.params.path || req.params.path === "/") {
2626
const to = self(req)
2727
return redirect(req, res, "login", {
2828
to: to !== "/" ? to : undefined,

0 commit comments

Comments
 (0)