custom-scripts/mccs-it/thermal/app.js
2024-09-10 13:29:16 -04:00

31 lines
847 B
JavaScript

const express = require('express');
const Thermal = require('./modules/Thermal.js');
const app = express();
const port = 80;
// Middleware to serve static files (HTML)
app.use(express.static('public'));
// Middleware to parse JSON request bodies
app.use(express.json());
// Test print function
app.post('/print', async (req, res) => {
try {
const { username, studentId } = req.body;
if (!username || !studentId) {
return res.status(400).json({ message: 'Username and Student ID are required.' });
}
await Thermal.printCredentials(username, studentId, req, res);
} 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}`);
});