Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
mvc-middleware
Advanced tools
Mvc middleware for express like .Net Mvc
import express, { Router } from 'express';
import { MvcMiddleware } from 'mvc-middleware';
const app = express();
MvcMiddleware.connect(app, Router);
app.listen(3000, 'localhost');
By default, place for controllers is my-project/controllers
.
You can specify your controller location:
import express, { Router } from 'express';
import { MvcMiddleware } from 'mvc-middleware';
const app = express();
const directoryPath = path.join(__dirname, 'src', 'some-folder', 'controllers');
new MvcMiddleware(app, Router)
.registerControllers(directoryPath)
.run();
app.listen(3000, 'localhost');
Controller sample:
my-project/controllers/users-controller.js
import { UserService } from '../domain/users';
import { ControllerBase } from './base/controller-base';
export class UsersController extends MvcController {
static area = '/users';
static get = {
'/api/users/list': 'list',
'/api/users/:userId': 'getById',
'/users': 'userListPage',
':userId': 'userPage',
}
static post = {
'/api/users/add': 'add',
}
constructor(request, response) {
super(request, response);
this.users = [{
id: 1,
name: 'user 1',
}];
}
// GET: /users
userListPage() {
return this.view('list');
}
// GET: /users/:userId
userPage(userId) {
return this.view('user');
}
// GET: /api/users/list
list() {
return this.ok(this.users);
}
// GET: /api/users/:userId
getById(userId) {
const user = this.users.find(user => user.id === userId);
return this.ok(user);
}
// POST: /api/users/add
add({ name }) {
this.users.push({
id: this.users.length + 1,
name,
});
return this.ok('user is added');
}
}
export default UsersController;
Default paths for views is my-project/public/views/*.html
and my-project/public/views/<controller area>/*.html
.
You change it by overriding getViewPath(viewName, area)
method of MvcController
.
ok
method of MvcController
returns data with 200 status code. You can pass plain text or object that will be transformed to json.
FAQs
Mvc middleware for express with API similar to .NET MVC
The npm package mvc-middleware receives a total of 7 weekly downloads. As such, mvc-middleware popularity was classified as not popular.
We found that mvc-middleware demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.