fix: remove bkp file, fix compose network, remove debug log
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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}`);
|
||||
});
|
||||
Reference in New Issue
Block a user