Code-Server and Live Preview #4963
-
Hey guys sorry to bother. I have code-server running on an old iMac using a Freenom domain, Cloudflare, and Caddy. I am accessing my code-server via https://mydomain and everything seems to be working fine except that I cannot preview my HTML files with the "Live Preview" extension. My Live Preview window is blank. As another option, I tried the "Five Server" live previewing extension, but it just opens a browser webpage that says "This site can't be reached" "127.0.0.1 refused to connect." Is this an HTTPS issue? WebSockets? Self-signed certificate? I was initially using port forwarding via SSH and accessing my code-server via 127.0.0.1:8080, but I encountered the same problem. Have I missed a critical step somewhere or is remotely previewing HTML files not possible using code-server? Any help would be appreciated, but do apologize if the terminology I am using is not exactly correct, and would just like to say thanks in advance to anyone who might be able to shed some light on this issue. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
Great question. Reading about "Live Preview", it says,
So if it's hosting a local server for you, would you need to forward that port as well? 🤔 I imagine you'd have to set something in your Caddy file to forward all ports on "127.0.0.1" but I don't know if that would work. Maybe @code-asher knows? |
Beta Was this translation helpful? Give feedback.
-
Yeah it does not look like the live preview extension has support for remote servers. Many of these extensions still assume they are running in local VS Code so they try to connect to localhost. Ideally the extension would have an option where you could set the URL so you can open it through code-server's proxy (I checked but did not see one) or it could detect it automatically from the One workaround is to manually use the proxy by going to https://domain.tld/proxy/3000/ (this is a path-rewriting proxy and assumes your preview server is running on 3000) or https://domain.tld/absproxy/3000/ (same deal except not a path-rewriting proxy). The next best thing would be forward your local port 3000 to your server. I tried a while back to automatically intercept localhost calls to replace them with the proxy but ran into some issues. Might be worth giving it another shot. |
Beta Was this translation helpful? Give feedback.
-
Super appreciative of you guys for taking the time out to lend a hand @jsjoeio @code-asher. At least now I know it's not supposed to work right out of the box. |
Beta Was this translation helpful? Give feedback.
-
For anyone who need, so when you need to do port or live preview. Then you need to have the url follow by proxy and port then the folder path to your acutall file. For example: /home/container/Code/JS/Color Flipper
[container@Code-Server Color Flipper]$ tree
.
├── index.html
├── script.js
└── style.css and the url have to be: https://codeserver.homeserverlocal.com/proxy/5500/Code/JS/Color%20Flipper/index.html i hope this help |
Beta Was this translation helpful? Give feedback.
Yeah it does not look like the live preview extension has support for remote servers. Many of these extensions still assume they are running in local VS Code so they try to connect to localhost.
Ideally the extension would have an option where you could set the URL so you can open it through code-server's proxy (I checked but did not see one) or it could detect it automatically from the
VSCODE_PROXY_URI
environment variable.One workaround is to manually use the proxy by going to https://domain.tld/proxy/3000/ (this is a path-rewriting proxy and assumes your preview server is running on 3000) or https://domain.tld/absproxy/3000/ (same deal except not a path-rewriting proxy).
The next best…