diff --git a/.gitea/workflows/trigger-github.yml b/.gitea/workflows/trigger-github.yml deleted file mode 100644 index 5731ec9..0000000 --- a/.gitea/workflows/trigger-github.yml +++ /dev/null @@ -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" - } - }' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b56f7f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +.DS_Store +*.log +.env diff --git a/Dockerfile b/Dockerfile index 7f9d020..7bfe5f1 100644 --- a/Dockerfile +++ b/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"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..6adc773 --- /dev/null +++ b/README.md @@ -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)_ diff --git a/docker-compose.yml b/docker-compose.yml index e8e1bfe..24c9f28 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: