2024-09-06 23:26:30 +00:00
|
|
|
const express = require('express');
|
2024-09-09 15:38:53 +00:00
|
|
|
const Thermal = require('./modules/Thermal.js');
|
2024-09-06 23:26:30 +00:00
|
|
|
|
|
|
|
const app = express();
|
2024-09-10 14:24:52 +00:00
|
|
|
const port = 80;
|
2024-09-06 23:26:30 +00:00
|
|
|
|
|
|
|
// Middleware to serve static files (HTML)
|
|
|
|
app.use(express.static('public'));
|
|
|
|
|
2024-09-09 20:27:51 +00:00
|
|
|
// Middleware to parse JSON request bodies
|
|
|
|
app.use(express.json());
|
|
|
|
|
2024-09-06 23:26:30 +00:00
|
|
|
// Test print function
|
2024-09-10 17:29:16 +00:00
|
|
|
app.post('/print', async (req, res) => {
|
2024-09-06 23:26:30 +00:00
|
|
|
try {
|
2024-09-09 20:27:51 +00:00
|
|
|
const { username, studentId } = req.body;
|
|
|
|
if (!username || !studentId) {
|
|
|
|
return res.status(400).json({ message: 'Username and Student ID are required.' });
|
|
|
|
}
|
2024-09-10 17:29:16 +00:00
|
|
|
await Thermal.printCredentials(username, studentId, req, res);
|
2024-09-06 23:26:30 +00:00
|
|
|
} catch (error) {
|
|
|
|
console.error('Print Error:', error);
|
|
|
|
res.status(500).json({ message: 'Print Error', error: error.message });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Start the server
|
|
|
|
app.listen(port, () => {
|
|
|
|
console.log(`Server running at http://localhost:${port}`);
|
|
|
|
});
|