首页 > 解决方案 > 在 gcp 云 shell 上运行代码服务器在预览时会出错

问题描述

我正在尝试在 gcp 云外壳上运行代码服务器。我下载了以下版本

https://github.com/cdr/code-server/releases/download/v3.9.2/code-server-3.9.2-linux-amd64.tar.gz我认为是正确的,提取了内容并跑了

code-server --auth none

这给出了以下输出

[2021-04-06T00:53:21.728Z] info  code-server 3.9.2 109d2ce3247869eaeab67aa7e5423503ec9eb859
[2021-04-06T00:53:21.730Z] info  Using user-data-dir ~/.local/share/code-server
[2021-04-06T00:53:21.751Z] info  Using config file ~/.config/code-server/config.yaml
[2021-04-06T00:53:21.751Z] info  HTTP server listening on http://127.0.0.1:8080
[2021-04-06T00:53:21.751Z] info    - Authentication is disabled
[2021-04-06T00:53:21.751Z] info    - Not serving HTTPS

现在,当我尝试Web Preview -> preview on port 8080什么都没发生时,我只是得到一个空白屏幕,在代码控制台上我看到以下错误

2021-04-06T00:50:04.470Z] 错误 vscode 握手超时 {"token":"e9b80ff7-10f9-4089-8497-b98688129452"}

我不确定我需要在这里做什么?

标签: google-cloud-platformcode-server

解决方案


  1. 在 cloud shell 编辑器中,创建一个扩展名为 .sh 的文件,并使用以下步骤安装代码服务器:

    export VERSION=`curl -s https://api.github.com/repos/cdr/code-server/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")'`
    
    wget https://github.com/cdr/code-server/releases/download/v3.10.2/code-server-3.10.2-linux-amd64.tar.gz
    
    tar -xvzf code-server-3.10.2-linux-amd64.tar.gz
    
    cd code-server-3.10.2-linux-amd64
    
  2. 使用终端运行 vscode.sh 文件: ./vscode.sh

    如果出现警告“权限被拒绝”,请键入chmod +x vscode.sh然后再次继续运行该文件。

  3. 要导航到文件夹: cd code-server-3.10.2-linux-amd64/

  4. 要导航到垃圾箱: cd bin/

  5. 启动服务器: ./code-server --auth none --port 8080

现在,您可以通过使用 web preview->preview on port 8080 选项或终端中的 HTTP 服务器链接在浏览器中查看 VSCode IDE。


推荐阅读