ipAddress
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v6View latest version
This Val Town project provides a simple service to help a React Native mobile app discover and connect to a restaurant server running on a desktop application.
In a restaurant management system where:
- A desktop application runs the server with APIs
- A React Native mobile app needs to connect to those APIs
- The server's IP address might change
This service acts as a bridge that allows the server to register its current IP address and the mobile app to discover it.
- Server Registration: When the desktop server starts, it sends its current IP address to this service
- Mobile App Discovery: The mobile app queries this service to get the latest server IP address
- Direct Connection: The mobile app then connects directly to the server using the discovered IP
POST /register
Authorization: Bearer YOUR_SECRET_TOKEN
Content-Type: application/json
{
"ipAddress": "192.168.1.100",
"port": 8080
}
GET /
Response:
{ "ipAddress": "192.168.1.100", "port": 8080, "updatedAt": "2023-06-15T12:34:56.789Z" }
- Uses Val Town's blob storage to persist the server IP address
- Includes basic token authentication for the registration endpoint
- Provides CORS headers to allow cross-origin requests from the mobile app
- Set the
SERVER_REGISTER_TOKENenvironment variable in Val Town for security - Configure the desktop server to call the registration endpoint on startup
- Configure the React Native app to query this service before making API calls