๐Ÿ“ฆ manideepk90 / hyperOTAServer

๐Ÿ“„ README.md ยท 163 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163# HyperOTA Server

A Node.js server for serving Over-The-Air (OTA) updates and configurations for mobile applications.

## Features

- Serves configuration files for Android and iOS apps
- Version-based configuration management
- File upload and download capabilities
- CORS enabled for cross-origin requests
- Automatic network interface detection

## Installation

```bash
npm install
# or
yarn install
```

## Running the Server

```bash
node server.js
```

The server will start on port 3000 (or the port specified in the PORT environment variable) and display all available network interfaces.

## API Endpoints

### Configuration Endpoints

#### Android Configuration

- **GET** `/mobile-ota/android/:version/config.json`
  - Returns configuration for the specified Android app version
  - Example: `/mobile-ota/android/1.0.0/config.json`

#### iOS Configuration

- **GET** `/mobile-ota/ios/:version/config.json`
  - Returns configuration for the specified iOS app version
  - Example: `/mobile-ota/ios/2.0.0/config.json`

### File Management Endpoints

#### List Files

- **GET** `/files` - Lists all files in the Android uploads directory

#### Download Files

- **GET** `/files/android/:filename` - Download a specific Android file
- **GET** `/files/ios/:filename` - Download a specific iOS file
- **GET** `/files/locale/:localeName` - Download a specific locale file

## Version-Based Configuration System

The server supports serving different configurations based on the app version. It follows this priority order:

1. **Version-specific config**: `ota/{version}/config.json`
2. **Default config**: `ota/default/config.json`
3. **Fallback config**:
   - Android: `config.json`
   - iOS: `ios-config2.json`

### Directory Structure

```
hyperOTAServer/
โ”œโ”€โ”€ server.js
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ config.json              # Fallback config for Android
โ”œโ”€โ”€ ios-config2.json         # Fallback config for iOS
โ”œโ”€โ”€ ota/                     # Version-based configs
โ”‚   โ”œโ”€โ”€ 1.0.0/
โ”‚   โ”‚   โ””โ”€โ”€ config.json
โ”‚   โ”œโ”€โ”€ 2.0.0/
โ”‚   โ”‚   โ””โ”€โ”€ config.json
โ”‚   โ””โ”€โ”€ default/
โ”‚       โ””โ”€โ”€ config.json
โ””โ”€โ”€ uploads/
    โ”œโ”€โ”€ android/
    โ”œโ”€โ”€ ios/
    โ””โ”€โ”€ locales/
```

### Configuration Examples

#### Version-specific configuration

When a client requests `/mobile-ota/ios/1.0.0/config.json`, the server will:

1. First look for `ota/1.0.0/config.json`
2. If not found, check `ota/default/config.json`
3. If still not found, use `ios-config2.json`

#### Setting up configurations

1. Create version-specific folders in the `ota` directory:

   ```bash
   mkdir -p ota/1.0.0
   mkdir -p ota/2.0.0
   mkdir -p ota/default
   ```

2. Place your `config.json` files in the appropriate folders

3. The server will automatically serve the correct configuration based on the requested version

### Example Configuration File

```json
{
  "version": "2",
  "config": {
    "version": "v2",
    "release_config_timeout": 2000,
    "boot_timeout": 2000,
    "properties": {}
  },
  "package": {
    "name": "Hyperswitch_SDK",
    "version": "v2",
    "properties": {
      "manifest": {},
      "manifest_hash": {}
    },
    "index": {
      "url": "http://localhost:3000/files/android/bundle-v1-android.zip",
      "filePath": "hyperswitch.bundle"
    },
    "important": [],
    "lazy": []
  },
  "resources": []
}
```

## Logging

The server logs:

- Startup information including all available network interfaces
- Which configuration file is being served for each request
- File access attempts and errors

## CORS Configuration

The server is configured to accept requests from any origin (`*`). Modify the CORS settings in `server.js` if you need to restrict access to specific domains.

## Environment Variables

- `PORT`: Server port (default: 3000)

## Error Handling

All endpoints include error handling and will return appropriate HTTP status codes:

- `404`: File or configuration not found
- `500`: Server error (e.g., failed to read configuration file)