ntfy-emergency-app/README.md

178 lines
4.4 KiB
Markdown
Raw Normal View History

2025-10-17 19:35:19 +02:00
# ntfy emergency app - Message Webapp
2025-10-16 09:50:36 +02:00
2025-10-17 19:35:19 +02:00
A simple web application that allows users to send emergency messages through an ntfy server.
2025-10-16 09:50:36 +02:00
2025-10-17 19:35:19 +02:00
## Installation
2025-10-16 09:50:36 +02:00
2025-10-17 19:35:19 +02:00
1. Install dependencies:
2025-10-16 09:50:36 +02:00
```bash
npm install
```
2025-10-17 19:35:19 +02:00
2. Configure environment variables:
2025-10-16 09:50:36 +02:00
```bash
2025-10-17 19:35:19 +02:00
export NTFY_URL="https://your-ntfy-server.com"
export NTFY_USER="your-username"
export NTFY_PASSWORD="your-password"
export PORT=3000 # optional, defaults to 3000
2025-10-16 09:50:36 +02:00
```
2025-10-17 19:35:19 +02:00
3. Run the application:
2025-10-16 09:50:36 +02:00
```bash
npm start
```
2025-10-17 19:35:19 +02:00
## Environment Variables
2025-10-16 09:50:36 +02:00
2025-10-17 19:35:19 +02:00
- `NTFY_URL`: URL of your ntfy server (required)
- `NTFY_USER`: Username for ntfy authentication (required)
- `NTFY_PASSWORD`: Password for ntfy authentication (required)
- `NTFY_TOPIC`: ntfy topic/channel to send messages to (optional, defaults to "emergencia")
- `PORT`: Port to run the application on (optional, defaults to 3000)
2025-10-16 09:50:36 +02:00
2025-10-17 19:35:19 +02:00
### Docker Registry Variables (Optional)
2025-10-16 12:08:18 +02:00
2025-10-17 19:35:19 +02:00
- `DOCKER_REGISTRY`: Custom registry to publish the image to (optional)
- `DOCKER_USERNAME`: Username/organization in the registry (optional)
- `DOCKER_TAG`: Tag for the Docker image (optional, defaults to "latest")
2025-10-16 12:08:18 +02:00
2025-10-17 19:35:19 +02:00
## Usage
2025-10-16 09:50:36 +02:00
2025-10-17 19:35:19 +02:00
1. Open your browser to `http://localhost:3000` (or the configured port)
2. Fill out the form with your name and message
3. Click "Send Message"
4. You'll receive confirmation if the message was sent successfully
2025-10-16 09:50:36 +02:00
2025-10-17 19:35:19 +02:00
## Deployment
2025-10-16 09:50:36 +02:00
2025-10-17 19:35:19 +02:00
### Option 1: Docker Compose (Recommended)
2025-10-16 09:50:36 +02:00
2025-10-17 19:35:19 +02:00
1. Create a `.env` file with your credentials:
2025-10-16 09:50:36 +02:00
```bash
2025-10-17 19:35:19 +02:00
NTFY_URL=https://your-ntfy-server.com
NTFY_USER=your-username
NTFY_PASSWORD=your-password
2025-10-16 09:55:32 +02:00
NTFY_TOPIC=emergencia
2025-10-16 09:50:36 +02:00
```
2025-10-17 19:35:19 +02:00
2. Run with Docker Compose:
2025-10-16 09:50:36 +02:00
```bash
docker-compose up -d
```
2025-10-17 19:35:19 +02:00
The application will be available at `http://localhost:3000`
2025-10-16 09:50:36 +02:00
2025-10-17 19:35:19 +02:00
### Option 2: Direct Installation
2025-10-16 09:50:36 +02:00
2025-10-17 19:35:19 +02:00
To deploy on a Linux server:
2025-10-16 09:50:36 +02:00
2025-10-17 19:35:19 +02:00
1. Upload files to the server
2. Install Node.js (version 14 or higher)
3. Configure environment variables
4. Run `npm install` to install dependencies
5. Run `npm start` to start the application
2025-10-16 09:50:36 +02:00
2025-10-17 19:35:19 +02:00
### systemd Example (optional)
2025-10-16 09:50:36 +02:00
2025-10-17 19:35:19 +02:00
Create file `/etc/systemd/system/ntfy-emergency-app.service`:
2025-10-16 09:50:36 +02:00
```ini
[Unit]
2025-10-16 12:08:18 +02:00
Description=NTFY Emergency App
2025-10-16 09:50:36 +02:00
After=network.target
[Service]
Type=simple
2025-10-17 19:35:19 +02:00
User=your-username
WorkingDirectory=/path/to/ntfy-emergency-app
Environment=NTFY_URL=https://your-ntfy-server.com
Environment=NTFY_USER=your-username
Environment=NTFY_PASSWORD=your-password
2025-10-16 09:55:32 +02:00
Environment=NTFY_TOPIC=emergencia
2025-10-16 09:50:36 +02:00
Environment=PORT=3000
ExecStart=/usr/bin/node server.js
Restart=always
[Install]
WantedBy=multi-user.target
```
2025-10-17 19:35:19 +02:00
Then:
2025-10-16 09:50:36 +02:00
```bash
sudo systemctl daemon-reload
2025-10-16 12:08:18 +02:00
sudo systemctl enable ntfy-emergency-app
sudo systemctl start ntfy-emergency-app
2025-10-16 09:50:36 +02:00
```
2025-10-17 19:35:19 +02:00
## Docker Image Publishing
2025-10-16 10:02:25 +02:00
2025-10-17 19:35:19 +02:00
### Manual Build and Publishing
2025-10-16 10:02:25 +02:00
2025-10-17 19:35:19 +02:00
#### Option 1: Without custom registry (Docker Hub)
2025-10-16 10:02:25 +02:00
```bash
2025-10-17 19:35:19 +02:00
# Build and publish
npm run docker:build-tag-push
2025-10-16 12:08:18 +02:00
```
2025-10-16 10:02:25 +02:00
2025-10-17 19:35:19 +02:00
#### Option 2: With custom registry
2025-10-16 12:08:18 +02:00
```bash
2025-10-17 19:35:19 +02:00
# Configure environment variables
export DOCKER_REGISTRY=your-registry.com
export DOCKER_USERNAME=your-username
2025-10-16 12:08:18 +02:00
export DOCKER_TAG=v1.0.0
2025-10-17 19:35:19 +02:00
# Build and publish
npm run docker:build-tag-push
2025-10-16 12:08:18 +02:00
```
2025-10-17 19:35:19 +02:00
#### Option 3: Manual
2025-10-16 12:08:18 +02:00
```bash
docker build -t ntfy-emergency-app .
2025-10-17 19:35:19 +02:00
docker tag ntfy-emergency-app your-registry/ntfy-emergency-app:latest
docker push your-registry/ntfy-emergency-app:latest
2025-10-16 10:02:25 +02:00
```
2025-10-17 19:35:19 +02:00
### Using with Private Registry
2025-10-16 10:02:25 +02:00
2025-10-17 19:35:19 +02:00
To use the image from a private registry:
2025-10-16 10:02:25 +02:00
```bash
2025-10-17 19:35:19 +02:00
# Authenticate with the registry
docker login your-registry.com
2025-10-16 10:02:25 +02:00
2025-10-17 19:35:19 +02:00
# Run the image
2025-10-16 10:02:25 +02:00
docker run -d \
2025-10-16 12:08:18 +02:00
--name ntfy-emergency-app \
2025-10-16 10:02:25 +02:00
-p 3000:3000 \
2025-10-17 19:35:19 +02:00
-e NTFY_URL=https://your-ntfy-server.com \
-e NTFY_USER=your-username \
-e NTFY_PASSWORD=your-password \
2025-10-16 10:02:25 +02:00
-e NTFY_TOPIC=emergencia \
2025-10-17 19:35:19 +02:00
your-registry.com/ntfy-emergency-app:latest
2025-10-16 10:02:25 +02:00
```
2025-10-17 19:35:19 +02:00
## Project Structure
2025-10-16 09:50:36 +02:00
```
2025-10-16 12:08:18 +02:00
ntfy-emergency-app/
2025-10-17 19:35:19 +02:00
├── server.js # Main Express server
├── package.json # Dependencies and scripts
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose orchestration
├── scripts/ # Helper scripts
│ ├── docker-tag.sh # Script to tag images
│ └── docker-push.sh # Script to publish images
2025-10-16 09:50:36 +02:00
├── public/
2025-10-17 19:35:19 +02:00
│ ├── index.html # Main page
│ └── style.css # CSS styles
└── README.md # This file
2025-10-16 09:50:36 +02:00
```
2025-10-17 19:35:19 +02:00
## Notes
2025-10-16 09:50:36 +02:00
2025-10-17 19:35:19 +02:00
- Messages are sent to the topic configured in `NTFY_TOPIC` (defaults to "emergencia")
- Message format is: "Name: Message"
- The application validates that both fields are complete before sending
2025-10-16 12:08:18 +02:00