• Townie
    AI
  • Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
xhaka

xhaka

ipAddress

Public
Like
ipAddress
Home
Code
3
examples
2
README.md
H
index.ts
Branches
1
Pull requests
Remixes
History
Environment variables
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.
Sign up now
Code
/
Code
/
Search
index.ts
https://xhaka--d64a3728364811f0b1a09e149126039e.web.val.run
README.md

Restaurant Server IP Registry

This Val Town project provides a robust service to help a React Native mobile app discover and connect to a restaurant server running on a desktop application, even when network conditions are challenging.

Problem Solved

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 or be difficult to determine
  • The mobile app and server might be on different networks

This service acts as a bridge that allows the server to register its current IP addresses and the mobile app to discover and test connectivity to the server.

How It Works

  1. Server Registration: When the desktop server starts, it sends both its local and public IP addresses to this service
  2. Mobile App Discovery: The mobile app queries this service to get the latest server IP addresses
  3. Connectivity Testing: The mobile app tests connectivity to both the local and public IPs to determine which one works
  4. Direct Connection: The mobile app then connects directly to the server using the working IP

Endpoints

Register Server IP (For Desktop Server)

POST /register
Authorization: Bearer YOUR_SECRET_TOKEN
Content-Type: application/json

{
  "ipAddress": "192.168.1.100",
  "port": 8080,
  "serverName": "MainRestaurantServer",
  "allIpAddresses": ["192.168.1.100", "10.0.0.15"]
}

Get Server IP (For Mobile App)

GET /

Response:

{ "localIpAddress": "192.168.1.100", "publicIpAddress": "203.0.113.10", "port": 8080, "serverName": "MainRestaurantServer", "updatedAt": "2023-06-15T12:34:56.789Z" }

Get All Servers

GET /list

Get Client IP (For Troubleshooting)

GET /client-ip

Test Connectivity (For Troubleshooting)

POST /test
Content-Type: application/json

{
  "testIp": "192.168.1.100",
  "testPort": 8080
}

Implementation Details

  • Uses Val Town's blob storage to persist server information
  • Stores both local and public IP addresses for each server
  • Includes basic token authentication for the registration endpoint
  • Provides CORS headers to allow cross-origin requests from the mobile app
  • Includes troubleshooting endpoints to help diagnose connectivity issues

Setup Instructions

  1. Set the SERVER_REGISTER_TOKEN environment variable in Val Town for security
  2. Configure the desktop server to call the registration endpoint on startup
  3. Configure the React Native app to use the provided example code

Troubleshooting

If you're having connectivity issues:

  1. Check Network: Make sure both devices are on the same network
  2. Firewall Settings: Ensure the server's firewall allows incoming connections on the API port
  3. IP Address: Use the manual connection option in the React Native app to try different IP addresses
  4. Port Forwarding: If connecting from outside the local network, set up port forwarding on your router
  5. VPN Issues: Disable any VPNs that might interfere with local network discovery

Example Code

The /examples directory contains:

  • server-registration.js - Example code for the desktop server to register its IP
  • react-native-client.js - Example React Native component with robust connectivity handling
HTTP
  • index.ts
    xhaka--d6…9e.web.val.run
Code
examplesREADME.md
H
index.ts
FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.