Debugging the Frontend
Debugging the Frontend
This document describes in detail how to debug a frontend app locally, including environment configuration, starting the server and handling cross-origin requests.
Overview
The frontend template generated in the App Center has to be served over HTTP locally so that its static files are reachable. For the app to talk to the backend service properly, you also need cross-origin configuration and a domain mapping.
Configuration steps
1. Modify the hosts file
To solve cross-origin problems, add a domain mapping to your local hosts file.
macOS:
/etc/hostsWindows:
C:\Windows\System32\drivers\etc\hostsLinux:
/etc/hostsAppend the following line to the end of the hosts file:
127.0.0.1 dev.gmssh.comNote
Editing the hosts file may require administrator rights. On macOS you can use sudo; on Windows, run your editor as administrator.
2. Start a local server
Open a terminal in the root of your frontend project (next to index.html) and pick a way to start the local server that suits your setup.
Option 1: use http-server (recommended)
npx http-server -p 10010 --corsParameters:
-p 10010: serve on port 10010--cors: enable Cross-Origin Resource Sharing (CORS) so the frontend can call the backend API-c-1: disable caching (optional, handy while developing)-o: open the browser automatically (optional)
Full command examples:
# Basic start
npx http-server -p 10010 --cors
# Development mode (no cache + open the browser)
npx http-server -p 10010 --cors -c-1 -oOption 2: use the VS Code Live Server extension
If you use VS Code, you can install the Live Server extension:
- Install the extension: search for "Live Server" in the VS Code extensions marketplace and install it
- Configure the port: search for "liveServer.settings.port" in the VS Code settings and set it to
10010 - Start the server: right-click
index.htmland choose "Open with Live Server"
Advantages of Live Server
- Live reload: the browser refreshes when files change
- Visual operation: no command line parameters to remember
- Native integration: works seamlessly with VS Code
Option 3: use another static server
With serve:
npx serve -s . -l 10010 --corsWith live-server:
npx live-server --port=10010 --host=127.0.0.1 --corsImportant
- Port consistency: make sure the port you start matches the port configured in the App Center
- CORS: CORS support is mandatory, otherwise the frontend cannot call the backend API
- Domain access: open
http://dev.gmssh.com:10010after startup, notlocalhost
Verify the server is running
When the server starts, you should see output like this:
Starting up http-server, serving ./
Available on:
http://127.0.0.1:10010
http://dev.gmssh.com:10010
Hit CTRL-C to stop the serverOpen http://dev.gmssh.com:10010 in a browser to confirm the server responds.
3. Configure the debug address
Enter the following in the DevTools access address:
http://dev.gmssh.com:10010Once that is configured, you can debug your frontend app inside the GM Desktop platform.
FAQ
Port already in use
If port 10010 is already taken, use another port:
npx http-server -p 8080 --corsRemember to update the port in the App Center configuration as well.
Cross-origin problems
Make sure that:
- The hosts file is configured correctly
- The server was started with the
--corsflag - The access address uses the configured domain instead of localhost
Cannot modify the hosts file
If you cannot modify the hosts file:
- macOS/Linux: use
sudo vim /etc/hostsorsudo nano /etc/hosts - Windows: run Notepad as administrator, then open the hosts file
Server fails to start
Common causes and fixes:
- Node.js is not installed: download and install it from nodejs.org
- Network problems: use a mirror
npx http-server -p 10010 --cors --registry=https://registry.npmmirror.com - Permission problems: make sure you can read and write in the project directory
Advanced configuration
Custom server configuration
You can create a configuration file to customise server behaviour:
Create a server.json configuration file:
{
"port": 10010,
"host": "0.0.0.0",
"cors": true,
"cache": 3600,
"showDir": false,
"autoIndex": true
}Start with the configuration file:
npx http-server -c-1 --cors -p 10010Using other static servers
Besides http-server, you can use other tools:
With serve:
npx serve -s . -l 10010 --corsWith live-server (supports live reload):
npx live-server --port=10010 --host=0.0.0.0 --corsDebugging tips
Common debugging commands
Check which process holds a port:
# macOS/Linux
lsof -i :10010
# Windows
netstat -ano | findstr :10010Test domain resolution:
ping web2.gmssh.comCheck the server status:
curl -I http://web2.gmssh.com:10010Security notes
Security warning
The configuration below is for development environments only. Do not use it in production:
- Only modify the hosts file while developing and restore it when you finish debugging
- Bind the local server to 127.0.0.1 only so it is not exposed to the public internet
- Stop the server when you are done so the port is not occupied for a long time
- Do not hard-code the debug domain in production code
