Skip to content

LiquidGalaxyLAB/lg-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

34 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LG Control Server πŸš€

The LG Control Server is a powerful and intuitive Node.js-based application for managing Liquid Galaxy (LG) systems via SSH. It offers a robust REST API to handle various LG operations, from visualizations to system management.

Server is Listening

View Swagger API Docs


πŸ“ Table of Contents

  1. Getting Started
  2. Project Structure
  3. How to Run
  4. Adding a New Command
  5. Endpoints
  6. License
  7. Contributors

πŸš€ Getting Started

Installation

  1. Clone the repository:

    git clone https://github.com/LiquidGalaxyLAB/lg-server.git
    cd lg-server
  2. Install dependencies:

    npm install
  3. Ngrok Setup Instructions

    • For executing the commands in the deployed front-end application

Prerequisites

  • A local server running on port 3000

Installation and Setup

a. Download and Install ngrok

  • Navigate to ngrok downloads

  • Macos

    brew install ngrok
  • Ubuntu

    sudo snap install ngrok
  • Download and extract the ngrok executable to your preferred location (windows)

b. Launch Tunnel

  • Open a new terminal window
  • Execute the following command:
    ngrok http 3000
  • Verify the tunnel is active when you see the forwarding URL in the terminal

c. Configure Frontend

  • Copy the HTTPS forwarding URL from the ngrok terminal (Example: https://a1b2c3d4.ngrok.io)

  • Update your frontend application's configuration with this URL

  • Note The ngrok terminal must remain open to maintain the tunnel connection. The free tier will generate a new URL each time you restart ngrok.


🚧 Project Structure

  • app.js: Entry point of the application.
  • server.js: Configures middleware, routes, and starts the server.
  • routers/: Defines API routes.
  • controllers/: Contains logic to handle API requests.
  • services/: Implements SSH interactions and reusable logic.

▢️ How to Run

  1. Start the server:

    npm run dev
  2. Verify the server is running by hitting the health check endpoint:

    curl http://localhost:8000/ping

    Expected Response:

    { "message": "pong@@" }

βž• Adding a New Command

Step 1: Create a Service Function

  1. In the services/ directory, add a new function:

    export const newCommandService = async (ip, port, username, password, command) => {  
        const client = new Client();  
        try {  
            await connectSSH(client, { ip, port: parseInt(port, 10), username, password });  
            const result = await executeCommand(client, command);  
            console.log("Command result:", result);  
            return result;  
        } catch (error) {  
            console.error("Error during SSH operations:", error);  
            return { success: false, message: error.message };  
        } finally {  
            client.end();  
        }  
    };  

Step 2: Add a Controller Method

  1. In controllers/, add the logic to handle the new command:

    newCommand = async (req, res) => {  
        const { ip, port, username, password, command } = req.body;  
        const response = await newCommandService(ip, port, username, password, command);  
        return res.status(200).json(response);  
    };  

Step 3: Define the Route

  1. Add a route in routers/index.js:

    router.route("/new-command").post(lgConnectionController.newCommand);  

Step 4: Test the Endpoint

  1. Use curl or Postman to test:

    curl -X POST http://localhost:8000/api/new-command \  
    -H "Content-Type: application/json" \  
    -d '{  
        "ip": "192.168.x.x",  
        "port": "22",  
        "username": "your-username",  
        "password": "your-password",  
        "command": "your-command"  
    }'  

🌐 Endpoints

Core Endpoints

Endpoint Method Description
/ping GET Health check endpoint.
/api/execute-orbit POST Executes an orbit command.
/api/clean-visualization POST Cleans LG visualizations.
/api/clean-logos POST Removes LG logos.
/api/relaunch-lg POST Relaunches the LG system.
/api/reboot-lg POST Reboots the LG system.
/api/stop-orbit POST Stops orbit visualization.
/api/clean-balloon POST Cleans balloon visualizations.
/api/new-command POST Executes a custom command.

πŸ““ License

This project is licensed under the MIT License.


🀝 Contributors

Contributors

Backend Developer

The backend is developed by Lovely Sehotra.

Frontend Designer

Designed by Mentor Yash.