custom-scripts/mccs-it/thermal/app.js

55 lines
1.5 KiB
JavaScript
Raw Normal View History

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-10 19:42:42 +00:00
// Print credentials
app.post('/print-credentials', 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 });
}
});
2024-09-12 16:24:02 +00:00
// Print temp password
app.post('/print-temp-pw', async (req, res) => {
try {
const { password } = req.body;
if (!password) {
return res.status(400).json({ message: 'Password is required.' });
}
await Thermal.printCredentials(password, req, res);
} catch (error) {
console.error('Print Error:', error);
res.status(500).json({ message: 'Print Error', error: error.message });
}
});
2024-09-10 19:42:42 +00:00
// Print Student MaineCC Info
app.post('/print-mcc', async (req, res) => {
try {
await Thermal.printStudentMaineCC(req, res);
} catch (error) {
console.error('Print Error:', error);
res.status(500).json({ message: 'Print Error', error: error.message });
}
});
2024-09-06 23:26:30 +00:00
// Start the server
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});