|
1 | | -# Java Electerm sync server |
| 1 | +# Java Electerm Sync Server |
2 | 2 |
|
3 | 3 | [](https://github.com/electerm/electerm-sync-server-java/actions) |
4 | 4 |
|
5 | | -A simple electerm data sync server. |
| 5 | +[English](README.md) | [中文](README_CN.md) |
6 | 6 |
|
7 | | -## Use |
| 7 | +A simple, lightweight data synchronization server for [Electerm](https://github.com/electerm/electerm), built with Java and Spark. It provides a REST API for syncing bookmarks, history, and other data across Electerm instances. |
8 | 8 |
|
9 | | -```bash |
10 | | -git clone git@github.com:electerm/electerm-sync-server-java.git |
11 | | -cd electerm-sync-server-java |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +- **Java 17**: Required for building and running the server. Download from [Adoptium](https://adoptium.net/) or your preferred JDK provider. |
| 12 | +- **Gradle**: Included via the Gradle Wrapper (`gradlew`), so no separate installation needed. |
| 13 | +- **Git**: For cloning the repository. |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +1. **Clone the repository**: |
| 18 | + |
| 19 | + ```bash |
| 20 | + git clone https://github.com/electerm/electerm-sync-server-java.git |
| 21 | + cd electerm-sync-server-java |
| 22 | + ``` |
| 23 | + |
| 24 | +2. **Set up the environment file**: |
| 25 | + |
| 26 | + ```bash |
| 27 | + cp sample.env .env |
| 28 | + ``` |
12 | 29 |
|
13 | | -# create env file, then edit .env |
14 | | -cp sample.env .env |
| 30 | + Edit `.env` with your preferred settings (see Configuration below). |
15 | 31 |
|
16 | | -## run |
17 | | -gradlew run |
| 32 | +## Configuration |
18 | 33 |
|
19 | | -## build |
20 | | -gradlew build |
| 34 | +The server uses environment variables from a `.env` file for configuration. Key settings include: |
21 | 35 |
|
22 | | -# would show something like |
23 | | -# server running at http://127.0.0.1:7837 |
24 | | -# Then you can use http://127.0.0.1:7837/api/sync as API Url in electerm custom sync |
| 36 | +- `JWT_SECRET`: A secret key for JWT token signing (generate a strong random string). |
| 37 | +- `JWT_USER_NAME`: Username for authentication. |
| 38 | +- `JWT_USER_PASSWORD`: Password for authentication. |
| 39 | +- `PORT`: Server port (default: 7837). |
| 40 | +- `DB_URL`: H2 database URL (default: embedded database). |
25 | 41 |
|
26 | | -# in electerm sync settings, set custom sync server with: |
27 | | -# server url: http://127.0.0.1:7837 |
28 | | -# JWT_SECRET: your JWT_SECRET in .env |
29 | | -# JWT_USER_NAME: one JWT_USER in .env |
| 42 | +Example `.env`: |
| 43 | + |
| 44 | +```properties |
| 45 | +JWT_SECRET=your-super-secret-key-here |
| 46 | +JWT_USER_NAME=admin |
| 47 | +JWT_USER_PASSWORD=securepassword |
| 48 | +PORT=7837 |
| 49 | +DB_URL=jdbc:h2:./electerm_sync_db |
30 | 50 | ``` |
31 | 51 |
|
32 | | -## Test |
| 52 | +**Security Note**: Never commit `.env` to version control. Use strong, unique values for secrets. |
| 53 | + |
| 54 | +## Running the Server |
33 | 55 |
|
| 56 | +### Development Mode |
| 57 | +For quick testing or development: |
| 58 | +```bash |
| 59 | +./gradlew run |
| 60 | +``` |
| 61 | +- Starts the server on `http://127.0.0.1:7837`. |
| 62 | +- Output will show: `server running at http://127.0.0.1:7837`. |
| 63 | +- Press `Ctrl+C` to stop. |
| 64 | + |
| 65 | +### Production Mode |
| 66 | +1. **Build the application**: |
| 67 | + ```bash |
| 68 | + ./gradlew build |
| 69 | + ``` |
| 70 | + |
| 71 | +2. **Extract the distribution**: |
| 72 | + ```bash |
| 73 | + tar -xvf build/distributions/electerm-sync-server-java.tar |
| 74 | + cd electerm-sync-server-java |
| 75 | + ``` |
| 76 | + |
| 77 | +3. **Run the server**: |
| 78 | + ```bash |
| 79 | + ./bin/electerm-sync-server-java |
| 80 | + ``` |
| 81 | + - Runs in the foreground. Use `&` to background it: `./bin/electerm-sync-server-java &`. |
| 82 | + - Access at `http://127.0.0.1:7837` (or your configured port). |
| 83 | + |
| 84 | +## Using with Electerm |
| 85 | + |
| 86 | +1. In Electerm, go to **Settings > Sync**. |
| 87 | +2. Select **Custom Sync Server**. |
| 88 | +3. Set: |
| 89 | + - **Server URL**: `http://127.0.0.1:7837` (or your server's URL). |
| 90 | + - **JWT Secret**: The `JWT_SECRET` from your `.env`. |
| 91 | + - **Username**: The `JWT_USER_NAME` from your `.env`. |
| 92 | +4. Save and sync your data. |
| 93 | + |
| 94 | +The API endpoint is `http://127.0.0.1:7837/api/sync`. |
| 95 | + |
| 96 | +## Testing |
| 97 | + |
| 98 | +Run the test suite: |
34 | 99 | ```bash |
35 | | -gradlew test |
| 100 | +./gradlew test |
36 | 101 | ``` |
| 102 | +- Uses JUnit for unit tests. |
| 103 | +- Reports are in `build/reports/tests/test/index.html`. |
| 104 | + |
| 105 | +## Customization |
| 106 | + |
| 107 | +### Writing Your Own Data Store |
37 | 108 |
|
38 | | -## Write your own data store |
| 109 | +The server uses an H2 database by default, but you can implement custom storage. |
39 | 110 |
|
40 | | -Just take [src/main/java/ElectermSync/FileStore.java](src/main/java/ElectermSync/FileStore.java) as an example, write your own read/write method. |
| 111 | +1. Implement the data store interface by extending or referencing `DataStore.java`. |
| 112 | +2. Update `App.java` to use your custom store. |
| 113 | +3. Rebuild and run. |
41 | 114 |
|
| 115 | +Example: Take [src/main/java/ElectermSync/DataStore.java](src/main/java/ElectermSync/DataStore.java) as a reference for read/write methods. |
42 | 116 |
|
43 | 117 | ## Docker |
44 | 118 |
|
45 | | -[https://github.com/Aliang-code/electerm-sync-server-java-docker](https://github.com/Aliang-code/electerm-sync-server-java-docker) |
| 119 | +For containerized deployment, see [electerm-sync-server-java-docker](https://github.com/Aliang-code/electerm-sync-server-java-docker). |
46 | 120 |
|
47 | | -## Sync server in other languages |
| 121 | +## Sync Servers in Other Languages |
48 | 122 |
|
49 | | -[https://github.com/electerm/electerm/wiki/Custom-sync-server](https://github.com/electerm/electerm/wiki/Custom-sync-server) |
| 123 | +Explore alternatives: [Custom Sync Server Wiki](https://github.com/electerm/electerm/wiki/Custom-sync-server). |
50 | 124 |
|
51 | 125 | ## License |
52 | 126 |
|
|
0 commit comments