chore: clean up repo, add README and .gitignore
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
name: Trigger GitHub Docker Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
trigger:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Trigger GitHub workflow
|
||||
run: |
|
||||
curl -X POST \
|
||||
-H "Accept: application/vnd.github+json" \
|
||||
-H "Authorization: Bearer ${{ secrets.PAT_GITHB }}" \
|
||||
https://api.github.com/repos/al3des/deploy/dispatches \
|
||||
-d '{
|
||||
"event_type": "build-docxtemplater",
|
||||
"client_payload": {
|
||||
"gitea_repo": "https://gitea.netcups.al3dev.link/al3dev/docxtemplater-server.git",
|
||||
"image": "gitea.netcups.al3dev.link/al3dev/docxtemplater-server:latest"
|
||||
}
|
||||
}'
|
||||
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
node_modules/
|
||||
.DS_Store
|
||||
*.log
|
||||
.env
|
||||
15
Dockerfile
15
Dockerfile
@@ -1,7 +1,16 @@
|
||||
FROM node:16-alpine
|
||||
FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files first for better layer caching
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
|
||||
# Install dependencies
|
||||
RUN npm ci --only=production
|
||||
|
||||
# Copy application code
|
||||
COPY . .
|
||||
|
||||
EXPOSE 3000
|
||||
CMD ["npm", "start"]
|
||||
|
||||
CMD ["node", "server.js"]
|
||||
|
||||
82
README.md
Normal file
82
README.md
Normal file
@@ -0,0 +1,82 @@
|
||||
# docxtemplater-server
|
||||
|
||||
A lightweight HTTP service for processing DOCX templates with JSON data.
|
||||
|
||||
## What It Does
|
||||
|
||||
This service accepts a DOCX template file and JSON data via HTTP POST, processes the template using [docxtemplater](https://docxtemplater.com/), and returns the generated document.
|
||||
|
||||
## API
|
||||
|
||||
### `POST /process-template`
|
||||
|
||||
Process a DOCX template with provided data.
|
||||
|
||||
**Request Format:**
|
||||
- Content-Type: `multipart/form-data`
|
||||
- Fields:
|
||||
- `template` (file): The DOCX template file
|
||||
- `data` (text): JSON string containing template variables
|
||||
|
||||
**Example using cURL:**
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/process-template \
|
||||
-F "template=@template.docx" \
|
||||
-F 'data={"name":"John Doe","date":"2026-03-21"}'
|
||||
```
|
||||
|
||||
**Response:**
|
||||
- Content-Type: `application/vnd.openxmlformats-officedocument.wordprocessingml.document`
|
||||
- Body: Generated DOCX file (binary)
|
||||
|
||||
**Error Responses:**
|
||||
- `400 Bad Request`: Missing template or data
|
||||
- `500 Internal Server Error`: Processing error
|
||||
|
||||
## Running Locally
|
||||
|
||||
### With Docker Compose (recommended)
|
||||
```bash
|
||||
docker-compose up
|
||||
```
|
||||
|
||||
The service will be available at `http://localhost:3000`.
|
||||
|
||||
### With Node.js
|
||||
```bash
|
||||
npm install
|
||||
npm start
|
||||
```
|
||||
|
||||
## Environment Variables
|
||||
|
||||
- `PORT` — Server port (default: `3000`)
|
||||
|
||||
## Template Syntax
|
||||
|
||||
Templates use docxtemplater syntax with curly braces:
|
||||
|
||||
```
|
||||
Hello {name}, today is {date}.
|
||||
```
|
||||
|
||||
Supports:
|
||||
- Simple variables: `{variable}`
|
||||
- Loops: `{#items}{name}{/items}`
|
||||
- Conditionals: `{#isActive}Active{/isActive}`
|
||||
|
||||
See [docxtemplater documentation](https://docxtemplater.com/docs/tag-types/) for full syntax.
|
||||
|
||||
## Development
|
||||
|
||||
**Build Docker image:**
|
||||
```bash
|
||||
docker build -t docxtemplater-server .
|
||||
```
|
||||
|
||||
**Run tests:**
|
||||
_(No tests currently configured)_
|
||||
|
||||
## License
|
||||
|
||||
_(License not specified)_
|
||||
@@ -3,14 +3,21 @@ version: '3.8'
|
||||
services:
|
||||
docxtemplater-service:
|
||||
build: .
|
||||
expose:
|
||||
- "3000"
|
||||
ports:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
- PORT=3000
|
||||
networks:
|
||||
- default
|
||||
- caddy_default
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:3000"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 10s
|
||||
|
||||
networks:
|
||||
default: {}
|
||||
caddy_default:
|
||||
|
||||
Reference in New Issue
Block a user