express-mvc-middleware
v1.0.10
Published
MVC-Middleware
Maintainers
Readme
Directory structure
├── models/ # Các mô hình AI
├── data/ # Xử lý dữ liệu
├── api/ # Các logic xử lý API
├── controllers/ # Các logic xử lý MVC
├── utils/ # Hàm tiện ích chung
├── app.js # Điểm bắt đầu chương trình
├── tests/ # Các unit test
├── logs/ # Log của ứng dụng
├── package.json # Thông tin dependencies
└── README.md # Hướng dẫn sử dụngRequire
Require folder controllers, each controller must be declared in the form
exports.example = function(req,res,next){
res.send("example");
}Express 4
const helpers = require('express-mvc-middleware');
const app = express();
app.all("*",helpers.autoloadController(app));
const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
console.log(`running on http://localhost:${PORT}`);
});Express 5
const helpers = require('express-mvc-middleware');
const app = express();
app.use(helpers.autoloadController(app));
const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
console.log(`running on http://localhost:${PORT}`);
});API ws web socket
Must have 4 functions
exports.onopen = (req, ws, next) =>{
}
exports.onmessage = (req, ws, next) => {
}
exports.oncolse = (req, ws, next) => {
}
exports.onerror = (req, ws, next) => {
}Note
In the onmessage event, if sent with format like this:
{
type:url,
text:'address',
body: {key1:'value1'},
method:"GET|POST....."
}it will inherit the api route.
