diff --git a/docker-compose.yml b/docker-compose.yml index 24c9f28..27bda76 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,9 +7,6 @@ services: - "3000:3000" environment: - PORT=3000 - networks: - - default - - caddy_default restart: unless-stopped healthcheck: test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:3000"] @@ -17,8 +14,3 @@ services: timeout: 10s retries: 3 start_period: 10s - -networks: - default: {} - caddy_default: - external: true diff --git a/server.js b/server.js index a190a5f..882b29c 100644 --- a/server.js +++ b/server.js @@ -31,7 +31,6 @@ app.post('/process-template', (req, res) => { // Find the template file from the uploaded files const templateFile = req.files?.find(file => file.fieldname === 'template'); const templateData = req.body?.data ? JSON.parse(req.body.data) : null; - console.log(templateData) if (!templateFile || !templateData) { return res.status(400).json({ error: 'Missing required fields', diff --git a/server.js.bkp b/server.js.bkp deleted file mode 100644 index 66560fa..0000000 --- a/server.js.bkp +++ /dev/null @@ -1,44 +0,0 @@ -const express = require('express'); -const fs = require('fs'); -const path = require('path'); -const Docxtemplater = require('docxtemplater'); -const PizZip = require('pizzip'); - -const app = express(); - -// Enable JSON parsing for incoming requests -app.use(express.json()); -app.use(express.urlencoded({ extended: false })); - -// Endpoint to generate the document -app.post('/generate-doc', (req, res) => { - try { - // Load your DOCX template (ensure the template is in the same directory) - const content = fs.readFileSync(path.resolve(__dirname, 'template.docx'), 'binary'); - const zip = new PizZip(content); - const doc = new Docxtemplater(zip, { paragraphLoop: true, linebreaks: true }); - - // Set your template variables from the request body - doc.setData(req.body); - - // Render the document (this only replaces placeholders, preserving your formatting) - doc.render(); - - // Generate the updated document as a buffer - const buf = doc.getZip().generate({ type: 'nodebuffer' }); - - res.set({ - 'Content-Type': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'Content-Disposition': 'attachment; filename=output.docx' - }); - res.send(buf); - } catch (error) { - console.error('Error during document generation:', error); - res.status(500).send('An error occurred while generating the document.'); - } -}); - -const PORT = process.env.PORT || 3000; -app.listen(PORT, () => { - console.log(`Docxtemplater service listening on port ${PORT}`); -});