[[:oktatas:web:back-end_framework:express|< Express]]
====== Express - Kontroller objektummal ======
* **Szerző:** Sallai András
* Copyright (c) 2024, Sallai András
* Szerkesztve: 2024
* Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]]
* Web: https://szit.hu
===== Hibakezelés leválasztása =====
const express = require('express');
const app = express();
const router = require('./routes');
const port = 8000;
app.use('/api',router);
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});
const Router = require('express');
const router = Router();
const EmployeeController = require('./controllers/employeecontroller');
router.get('/employees', EmployeeController.index);
module.exports = router;
const EmployeeController = {
index(req, res) {
try {
EmployeeController.tryIndex(req, res);
} catch (error) {
res.status(500);
res.json({msg: error});
}
},
tryIndex(req, res) {
res.status(200);
res.json({msg: 'működik'});
}
}
module.exports = EmployeeController;