# Synology Deployment

## Container Manager

1. Copy this repository or the NAS deploy ZIP to the NAS.
2. Extract it into a persistent folder, for example
   `/docker/cargoradar`.
3. Create `.env` from `.env.example`.
4. Set `CARGORADAR_PORT` and, if needed, `ADMIN_TOKEN`.
5. Create a Container Manager project from `docker-compose.yml`.
6. Keep `runtime-data` mapped to persistent NAS storage.

## Verified NAS Setup

The first NAS deployment was verified on 2026-06-06 with:

```text
Project name: cargoradar
Project path: /volume1/docker/cargoradar/current
LAN URL:      http://192.168.200.129:18081
Public URL:   https://cargoradar.comtropy.synology.me
```

The Container Manager build should end with `Exit Code: 0`, and the server
health check should report `Health: ok`.

Keep the real `ADMIN_TOKEN` in the NAS `.env` file, not in committed docs.
When creating `.env` remotely, make sure each setting is on its own real line;
literal `\n` text inside the file will break Docker Compose port parsing.

The current reverse proxy rule is:

```text
Source: HTTPS cargoradar.comtropy.synology.me:443
Target: HTTP  localhost:18081
```

If browsers show an HTTPS trust warning, assign or issue a certificate that
covers `cargoradar.comtropy.synology.me`. The reverse proxy can still be smoke
tested with `curl -k` while the certificate is being prepared.

## Environment

```text
CARGORADAR_PORT=8080
ADMIN_TOKEN=
ADMIN_AUTH_REQUIRED=false
KAKAO_JAVASCRIPT_KEY=07f4728599ceaf4299f77c772a135423
SIMULATOR_ENABLED=true
SIMULATOR_INTERVAL_MS=4000
```

For NAS deployment, start from `.env.nas.example` instead. The recommended NAS
host port is `18081` because `18080` is already forwarded for `opendaw`.

```text
CARGORADAR_PORT=18081
ADMIN_TOKEN=change_this_admin_token
ADMIN_AUTH_REQUIRED=false
KAKAO_JAVASCRIPT_KEY=07f4728599ceaf4299f77c772a135423
SIMULATOR_ENABLED=true
SIMULATOR_INTERVAL_MS=4000
```

`ADMIN_AUTH_REQUIRED=false` keeps the sample control screen open regardless of
the entered admin token. For real operation, set `ADMIN_AUTH_REQUIRED=true` and
use a strong `ADMIN_TOKEN`.
Set `SIMULATOR_ENABLED=false` when real Android phones are ready to provide
driver locations.
If opening the app directly by port, use:

```text
http://<NAS-LAN-IP>:18081/?adminToken=<ADMIN_TOKEN>
```

The better public route is Synology Reverse Proxy:

```text
https://cargoradar.comtropy.synology.me -> http://127.0.0.1:18081
```

## Kakao Domain Entries

Register every origin that opens the control screen:

```text
http://localhost:8080
http://127.0.0.1:8080
http://192.168.200.129:18081
http://<NAS-LAN-IP>:18081
https://cargoradar.comtropy.synology.me
https://<NAS-domain>
```

Until the NAS origin is registered in Kakao Developers, the control screen can
still show driver/location data but the map area will display a Kakao key or
domain warning.

## Android URL

On the same LAN, use:

```text
http://<NAS-LAN-IP>:18081
```

When reverse proxy and HTTPS are ready, use:

```text
https://cargoradar.comtropy.synology.me
```

## Smoke Test

After deployment, run from a PC that can reach the NAS:

```powershell
.\scripts\health-check.ps1 -BaseUrl "http://<NAS-LAN-IP>:18081" -AdminToken "<ADMIN_TOKEN>"
.\scripts\post-demo-location.ps1 -BaseUrl "http://<NAS-LAN-IP>:18081"
```

Then open the control screen and confirm that the demo location appears in the
`위치` tab.

## Local Package

Create a NAS-ready ZIP from the repository root:

```powershell
.\scripts\package-nas-deploy.ps1
```

Upload the resulting `dist/cargoradar-nas-*.zip` to the NAS and extract it into
the deployment folder.

## Current Router Context

Known forwarding entries:

```text
50001 -> 192.168.200.129:5000  DSM HTTP
50002 -> 192.168.200.129:5001  DSM HTTPS
80    -> 192.168.200.129:80    Web Station / reverse proxy
443   -> 192.168.200.129:443   HTTPS reverse proxy
3000  -> 192.168.200.129:3000  Gitea
2222  -> 192.168.200.129:2222  Gitea SSH
50022 -> 192.168.200.129:22    SSH
18080 -> 192.168.200.129:18080 opendaw
```

Do not use `18080` for CargoRadar. Prefer a NAS-only host port such as `18081`
and publish it through reverse proxy on `443`.
