-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
123 lines (93 loc) · 4.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const express = require('express');
const cors = require('cors');
const app = express();
const PORT = process.env.PORT || 3000;
// Middleware to parse JSON requests
app.use(express.json());
// CORS middleware
app.use(cors());
app.use(express.static('public'));
// Define a route to serve index.html
// app.get('/', (req, res) => {
// res.sendFile(path.join(__dirname, 'public', 'index.html'));
// });
app.get('/', (req, res) => {
// res.sendFile(path.join(__dirname, 'public', 'index.html'));
const teamID = req.query.teamID;
const memberName = req.query.member;
// res.send(`Team ID: ${teamID}, Member Name: ${memberName}`);
res.json({ teamID: teamID, memberName: memberName });
// res.send(generateCertificate(teamID, memberName));
});
// Define a sample route
// app.get('/', (req, res) => {
// res.send('Hello World!');
// });
// Start the server
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
// const express = require('express');
// const app = express();
// const PORT = process.env.PORT || 3000;
// // Middleware to parse JSON requests
// app.use(express.json());
// app.use(express.static('public'));
// // Define a route to serve index.html
// app.get('/', (req, res) => {
// // res.sendFile(path.join(__dirname, 'public', 'index.html'));
// const teamID = req.query.teamID;
// const memberName = req.query.member;
// // res.send(`Team ID: ${teamID}, Member Name: ${memberName}`);
// res.send(generateCertificate(teamID, memberName));
// function generateCertificate(teamID, memberName) {
// const { jsPDF } = window.jspdf;
// const imgUrl = 'public/certificate-template.png'; // Path to your certificate image
// const img = new Image();
// img.src = imgUrl;
// img.onload = function () {
// // Get the image dimensions in pixels
// const imgWidthPx = img.width;
// const imgHeightPx = img.height;
// // Convert pixels to millimeters (1 px = 0.264583 mm)
// const imgWidthMm = imgWidthPx * 0.264583;
// const imgHeightMm = imgHeightPx * 0.264583;
// // Create a new PDF with dimensions matching the image
// const doc = new jsPDF({
// orientation: 'landscape',
// unit: 'mm',
// compressPdf: true,
// format: [imgWidthMm, imgHeightMm] // Set page size to the image size
// });
// // Add the image to the PDF without scaling
// doc.addImage(img, 'PNG', 0, 0, imgWidthMm, imgHeightMm);
// // Set font style, size, and color
// doc.setFont('helvetica','Bold'); // Font: helvetica, Style: bold
// doc.setFontSize(28); // Set font size to 28
// doc.setTextColor(0, 0, 0); // Set text color to blue (RGB)
// // Center the text horizontally
// // const teamIDText = `${teamID}`;
// // const memberNameText = `${memberName}`;
// const teamIDText = teamID ;
// const memberNameText = memberName ;
// const teamIDTextWidth = doc.getTextWidth(teamIDText);
// const memberNameTextWidth = doc.getTextWidth(memberNameText);
// // Position the text at the center of the page
// const xPosTeamID = (imgWidthMm - teamIDTextWidth) / 2;
// const xPosMemberName = (imgWidthMm - memberNameTextWidth) / 2;
// // Add the text
// doc.text(teamIDText, 95, imgHeightMm - 26); // 40 mm from the bottom for Team ID
// doc.text(memberNameText, xPosMemberName, imgHeightMm - 180); // 20 mm from the bottom for Member Name
// // Save the PDF
// doc.save(`${memberName}_certificate.pdf`);
// res.send("successful");
// };
// });
// // Define a sample route
// // app.get('/', (req, res) => {
// // res.send('Hello World!');
// // });
// // Start the server
// app.listen(PORT, () => {
// console.log(`Server running on port ${PORT}`);
// });