Initial commit: DOCX Template Server mit API und Tabellen-Support
- ✅ Node.js/Express Server mit DOCX Template-Verarbeitung - ✅ Automatische Tag-Erkennung und Demo-Daten-Generierung - ✅ Tabellen-Unterstützung mit Schleifen-Tags - ✅ REST-API /api/process-template für externe Integration - ✅ Web-Oberfläche mit vollständiger Dokumentation - ✅ SSL-Unterstützung (HTTPS Port 443 öffentlich) - ✅ Intelligente Spaltenerkennung für Tabellen - ✅ Detaillierte Statusmeldungen für alle Operationen - ✅ Flexible Custom-Daten + Auto-Generierung - ✅ Template- und Dokument-Management APIs
This commit is contained in:
328
README.md
Normal file
328
README.md
Normal file
@@ -0,0 +1,328 @@
|
||||
# DOCX Template Server
|
||||
|
||||
Ein Node.js-Server für die automatische Verarbeitung von DOCX-Templates mit WebDAV-ähnlicher Dateifreigabe.
|
||||
|
||||
## ✨ Features
|
||||
|
||||
- 📄 **Automatische DOCX-Template-Verarbeitung** mit docxtemplater
|
||||
- 🎯 **Intelligente Tag-Erkennung** und automatische Demo-Daten-Generierung
|
||||
- 📊 **Tabellen und Listen** - Unterstützung für komplexe Datenstrukturen
|
||||
- 🌐 **Dateifreigabe** - Lesen und Schreiben von Templates und Dokumenten
|
||||
- 🔒 **SSL-Ready** - Vorbereitet für HTTPS mit Let's Encrypt
|
||||
- 🎨 **Web-Interface** - Einfache Bedienung über Browser
|
||||
- 🚀 **Ein-Klick-Start** - Automatische Installation und Konfiguration
|
||||
|
||||
## 🚀 Schnellstart
|
||||
|
||||
```bash
|
||||
# Server starten
|
||||
./start.sh
|
||||
|
||||
# Oder manuell:
|
||||
npm install
|
||||
npm start
|
||||
```
|
||||
|
||||
## 🌐 Zugriff
|
||||
|
||||
- **Web-Interface:** http://localhost:80
|
||||
- **Templates:** http://localhost:80/webdav/templates/
|
||||
- **Dokumente:** http://localhost:80/webdav/documents/
|
||||
|
||||
## 📋 Verwendung
|
||||
|
||||
### 1. Template erstellen
|
||||
Erstellen Sie ein DOCX-Dokument mit Tags wie:
|
||||
- `{firma}` - wird zu Firmennamen
|
||||
- `{vorname}` `{nachname}` - werden zu Namen
|
||||
- `{email}` `{telefon}` - werden zu Kontaktdaten
|
||||
- `{#items}...{/items}` - wird zu Tabellendaten
|
||||
|
||||
### 2. Template hochladen
|
||||
- Über Web-Interface: Datei auswählen und hochladen
|
||||
- Über API: `POST /upload-template`
|
||||
- Über Dateifreigabe: Datei in `/webdav/templates/` kopieren
|
||||
|
||||
### 3. Automatische Verarbeitung
|
||||
Der Server erkennt automatisch alle Tags und füllt sie mit passenden Demo-Daten:
|
||||
|
||||
```json
|
||||
{
|
||||
"firma": "Mustermann GmbH",
|
||||
"vorname": "Max",
|
||||
"nachname": "Mustermann",
|
||||
"email": "max@example.com",
|
||||
"telefon": "+49 123 456789",
|
||||
"items": [
|
||||
{"items_name": "Produkt 1", "items_value": "100.00", "items_date": "01.01.2024"},
|
||||
{"items_name": "Produkt 2", "items_value": "200.00", "items_date": "02.01.2024"}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 🏷️ Unterstützte Tag-Typen
|
||||
|
||||
### Einfache Tags
|
||||
| Tag-Pattern | Generierte Daten | Beispiel |
|
||||
|-------------|------------------|----------|
|
||||
| `{name}`, `{vorname}` | Vorname | Max |
|
||||
| `{nachname}`, `{surname}` | Nachname | Mustermann |
|
||||
| `{email}`, `{mail}` | E-Mail | max@example.com |
|
||||
| `{telefon}`, `{phone}` | Telefon | +49 123 456789 |
|
||||
| `{adresse}`, `{address}` | Adresse | Musterstraße 123 |
|
||||
| `{stadt}`, `{city}` | Stadt | Berlin |
|
||||
| `{plz}`, `{postal}` | PLZ | 12345 |
|
||||
| `{datum}`, `{date}` | Datum | 02.10.2025 |
|
||||
| `{betrag}`, `{preis}`, `{amount}` | Geldbetrag | 1.234,56 |
|
||||
| `{firma}`, `{company}` | Firmenname | Mustermann GmbH |
|
||||
| `{nummer}`, `{id}` | Nummer | 123456 |
|
||||
|
||||
### Tabellen/Listen Tags
|
||||
```docx
|
||||
{#items}
|
||||
• {items_name}: {items_value} EUR (vom {items_date})
|
||||
{/items}
|
||||
```
|
||||
|
||||
Wird zu:
|
||||
```
|
||||
• Produkt 1: 100.00 EUR (vom 01.01.2024)
|
||||
• Produkt 2: 200.00 EUR (vom 02.01.2024)
|
||||
• Produkt 3: 300.00 EUR (vom 03.01.2024)
|
||||
```
|
||||
|
||||
## 🔧 API Endpunkte
|
||||
|
||||
### Templates verwalten
|
||||
```bash
|
||||
# Alle Templates auflisten
|
||||
GET /api/templates
|
||||
|
||||
# Template hochladen und verarbeiten
|
||||
POST /upload-template
|
||||
Content-Type: multipart/form-data
|
||||
Body: template=<file>
|
||||
|
||||
# Test-Template erstellen
|
||||
GET /create-test-template
|
||||
```
|
||||
|
||||
### Dokumente verwalten
|
||||
```bash
|
||||
# Alle Dokumente auflisten
|
||||
GET /api/documents
|
||||
|
||||
# Template mit eigenen Daten verarbeiten
|
||||
POST /api/process-template/:templateName
|
||||
Content-Type: application/json
|
||||
Body: {
|
||||
"firma": "Meine Firma",
|
||||
"vorname": "John",
|
||||
"nachname": "Doe",
|
||||
"items": [
|
||||
{"items_name": "Service A", "items_value": "500.00"}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 💾 Dateifreigabe Setup
|
||||
|
||||
### Windows Explorer
|
||||
1. Windows Explorer öffnen
|
||||
2. Adressleiste: `\\localhost\webdav$`
|
||||
3. Oder: "Netzlaufwerk verbinden" → `http://localhost:80/webdav/templates/`
|
||||
|
||||
### Linux/macOS
|
||||
```bash
|
||||
# Verzeichnis erstellen
|
||||
sudo mkdir -p /mnt/docx-templates
|
||||
sudo mkdir -p /mnt/docx-documents
|
||||
|
||||
# Mounten (davfs2 erforderlich)
|
||||
sudo mount -t davfs http://localhost:80/webdav/templates/ /mnt/docx-templates
|
||||
sudo mount -t davfs http://localhost:80/webdav/documents/ /mnt/docx-documents
|
||||
|
||||
# Oder über GUI: Dateimanager → "Mit Server verbinden" → http://localhost:80/webdav/templates/
|
||||
```
|
||||
|
||||
## 🔒 SSL/HTTPS Einrichtung
|
||||
|
||||
### Automatisches Setup
|
||||
```bash
|
||||
# SSL-Setup-Assistent starten
|
||||
./setup-ssl.sh
|
||||
```
|
||||
|
||||
### Manuelle Konfiguration
|
||||
|
||||
#### Option 1: Selbstsigniert (für Tests)
|
||||
```bash
|
||||
openssl req -x509 -newkey rsa:4096 -keyout private-key.pem -out certificate.pem -days 365 -nodes
|
||||
```
|
||||
|
||||
#### Option 2: Let's Encrypt (für Produktion)
|
||||
```bash
|
||||
# Certbot installieren
|
||||
sudo apt install certbot
|
||||
|
||||
# Zertifikat anfordern
|
||||
sudo certbot certonly --standalone -d ihre-domain.com
|
||||
|
||||
# Zertifikate verlinken
|
||||
ln -sf /etc/letsencrypt/live/ihre-domain.com/privkey.pem private-key.pem
|
||||
ln -sf /etc/letsencrypt/live/ihre-domain.com/fullchain.pem certificate.pem
|
||||
```
|
||||
|
||||
#### SSL aktivieren
|
||||
In `server.js` die SSL-Sektion uncommentieren:
|
||||
```javascript
|
||||
const sslOptions = {
|
||||
key: fs.readFileSync('private-key.pem'),
|
||||
cert: fs.readFileSync('certificate.pem')
|
||||
};
|
||||
|
||||
https.createServer(sslOptions, app).listen(443, () => {
|
||||
console.log('HTTPS Server läuft auf Port 443');
|
||||
});
|
||||
```
|
||||
|
||||
## 📁 Verzeichnisstruktur
|
||||
|
||||
```
|
||||
/home/OfficeServerJS/
|
||||
├── server.js # Hauptserver-Datei
|
||||
├── package.json # Node.js Abhängigkeiten
|
||||
├── start.sh # Server-Start-Script
|
||||
├── setup-ssl.sh # SSL-Setup-Assistent
|
||||
├── create_template.js # Template-Erstellungs-Tool
|
||||
├── templates/ # DOCX-Templates (Eingabe)
|
||||
│ ├── test_template.docx
|
||||
│ └── rechnung_template.docx
|
||||
├── documents/ # Generierte Dokumente (Ausgabe)
|
||||
│ ├── test_template_ausgefuellt.docx
|
||||
│ └── rechnung_template_ausgefuellt.docx
|
||||
├── uploads/ # Temporäre Upload-Dateien
|
||||
├── private-key.pem # SSL Privater Schlüssel (falls SSL aktiviert)
|
||||
└── certificate.pem # SSL Zertifikat (falls SSL aktiviert)
|
||||
```
|
||||
|
||||
## 🛠️ Anpassungen
|
||||
|
||||
### Neue Tag-Typen hinzufügen
|
||||
In `server.js` → `DemoDataGenerator.generateData()`:
|
||||
```javascript
|
||||
if (lowerTag.includes('neuer_tag') || lowerTag.includes('new_tag')) {
|
||||
data[tag] = 'Ihre eigene Daten-Generierung hier';
|
||||
}
|
||||
```
|
||||
|
||||
### Port ändern
|
||||
```bash
|
||||
export PORT=3000
|
||||
./start.sh
|
||||
```
|
||||
|
||||
### Unterschiedliche Demo-Daten-Sets
|
||||
```javascript
|
||||
// In server.js
|
||||
const demoDataSets = {
|
||||
'german': { /* deutsche Demo-Daten */ },
|
||||
'english': { /* englische Demo-Daten */ },
|
||||
'business': { /* Business Demo-Daten */ }
|
||||
};
|
||||
```
|
||||
|
||||
## 🚦 Produktions-Deployment
|
||||
|
||||
### 1. Server vorbereiten
|
||||
```bash
|
||||
# System aktualisieren
|
||||
sudo apt update && sudo apt upgrade -y
|
||||
|
||||
# Node.js installieren
|
||||
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
|
||||
sudo apt-get install -y nodejs
|
||||
|
||||
# Firewall konfigurieren
|
||||
sudo ufw allow 80
|
||||
sudo ufw allow 443
|
||||
sudo ufw enable
|
||||
```
|
||||
|
||||
### 2. SSL einrichten
|
||||
```bash
|
||||
./setup-ssl.sh
|
||||
# Option 2 wählen für Let's Encrypt
|
||||
```
|
||||
|
||||
### 3. Process Manager (PM2)
|
||||
```bash
|
||||
npm install -g pm2
|
||||
|
||||
# Server mit PM2 starten
|
||||
pm2 start server.js --name docx-server
|
||||
|
||||
# Auto-Start bei Neustart
|
||||
pm2 startup
|
||||
pm2 save
|
||||
```
|
||||
|
||||
### 4. Nginx Reverse Proxy (optional)
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name ihre-domain.com;
|
||||
|
||||
location / {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 🔍 Troubleshooting
|
||||
|
||||
### Server startet nicht
|
||||
```bash
|
||||
# Port-Konflikt prüfen
|
||||
sudo netstat -tlnp | grep :80
|
||||
|
||||
# Berechtigungen prüfen
|
||||
ls -la private-key.pem certificate.pem
|
||||
```
|
||||
|
||||
### Templates werden nicht verarbeitet
|
||||
- DOCX-Datei korrekt formatiert?
|
||||
- Tags richtig geschrieben (`{tag}` nicht `{{tag}}`)?
|
||||
- Datei-Berechtigungen prüfen
|
||||
|
||||
### Dateifreigabe funktioniert nicht
|
||||
```bash
|
||||
# WebDAV-Client installieren
|
||||
# Ubuntu/Debian:
|
||||
sudo apt install davfs2
|
||||
|
||||
# macOS:
|
||||
brew install davfs2
|
||||
```
|
||||
|
||||
### SSL-Probleme
|
||||
```bash
|
||||
# Zertifikat prüfen
|
||||
openssl x509 -in certificate.pem -text -noout
|
||||
|
||||
# Berechtigungen prüfen
|
||||
chmod 600 private-key.pem
|
||||
chmod 644 certificate.pem
|
||||
```
|
||||
|
||||
## 📞 Support
|
||||
|
||||
- **Logs:** `journalctl -u docx-server -f` (bei PM2: `pm2 logs`)
|
||||
- **Status:** `pm2 status` oder `ps aux | grep node`
|
||||
- **Konfiguration:** Alle Einstellungen in `server.js`
|
||||
|
||||
## 📄 Lizenz
|
||||
|
||||
MIT License - Frei verwendbar für kommerzielle und private Projekte.
|
||||
Reference in New Issue
Block a user