![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@egodigital/express-controllers
Advanced tools
Sets up controllers, which are running with Express.js.
Execute the following command from your project folder, where your package.json
file is stored:
npm install --save @egodigital/express-controllers
# install modules
npm install
# build
npm run build
First create a root directory, where all your controllers will be stored and implemented, lets say /controllers
.
Then create a /controllers/index.ts
(if using TypeScript) and implement an exported / public Controller
class with the following skeleton:
import * as joi from 'joi';
import { Request, Response } from 'express';
import { ControllerBase, GET, POST } from '@egodigital/express-controllers';
interface INewUser {
email?: string;
password: string;
username: string;
}
const NEW_USER_SCHEMA = joi.object({
email: joi.string()
.optional(),
password: joi.string()
.min(1)
.required(),
username: joi.string()
.required(),
});
/**
* /controllers/index.ts
*
* Base path: '/'
*/
export class Controller extends ControllerBase {
/**
* [GET] / endpoint
*
* 'index' will mapped to realtive '/' path by default.
*/
@GET()
public async index(req: Request, res: Response) {
return res.status(200)
.send('Hello, e.GO!');
}
/**
* [GET] /foo endpoint
*
* Other method names than 'index', will always be mapped
* to realtive '/{METHOD_NAME}' path
*/
@GET()
public async foo(req: Request, res: Response) {
return res.status(200)
.send('Hello, foo!');
}
/**
* [POST] /foo/:foo_id endpoint
*
* Define relative path explicitly.
*/
@POST('/foo/:foo_id')
public async foo_with_post(req: Request, res: Response) {
return res.status(200)
.send('Hello, foo.POST: ' + req.params['foo_id']);
}
/**
* [POST] /users endpoint
*
* Check JSON input via joi schema.
*/
@POST({
path: '/users',
schema: NEW_USER_SCHEMA,
})
public async create_new_user(req: Request, res: Response) {
const NEW_USER: INewUser = req.body;
// TODO ...
return res.status(200)
.send('Created new user: ' + NEW_USER.username);
}
}
For loading and initializing the controllers from /controllers
, simply create a /index.ts
file and use the following code snippet:
import * as express from 'express';
import { initControllers } from '@egodigital/express-controllers';
const app = express();
initControllers({
app,
cwd: __dirname + '/controllers',
});
app.listen(8080, () => {
// server now running
});
The library will scan the complete /controllers
folder structure and map the endpoints by that structure.
You can also use other filenames as index.ts
. For example, if you would like to implement a /foo/bar
endpoint, create a /controllers/foo/bar.ts
and use the following snippet:
import { Request, Response } from 'express';
import { ControllerBase, GET } from '@egodigital/express-controllers';
/**
* /controllers/foo/bar.ts
*
* Base path: '/foo/bar'
*/
export class Controller extends ControllerBase {
/**
* [GET] /foo/bar endpoint
*/
@GET()
public async index(req: Request, res: Response) {
// TODO
}
/**
* [GET] /foo/bar/xyz endpoint
*/
@GET()
public async xyz(req: Request, res: Response) {
// TODO
}
/**
* [GET] /foo/bar/tm endpoint
*/
@GET('/tm')
public async xyz(req: Request, res: Response) {
// TODO
}
}
import { Request, Response } from 'express';
import { ControllerBase, GET, ResponseSerializerContext } from '@egodigital/express-controllers';
/**
* /controllers/index.ts
*
* Base path: '/'
*/
export class Controller extends ControllerBase {
// serialize the results of any
// controller route method and
// send each as response
public __serialize(context: ResponseSerializerContext) {
return context.response
.header('Content-Type', 'application/json')
.send(JSON.stringify(
context.result // result of 'index()', e.g.
));
}
/**
* [GET] / relative endpoint
*/
@GET()
public async index(req: Request, res: Response) {
// this object is serialized and
// send by '__serialize()' (s. above)
return {
success: true,
data: {
'TM': '1979-09-05 23:09'
},
};
}
}
import * as express from 'express';
import { ControllerBase, POST } from '@egodigital/express-controllers';
interface INewUser {
email?: string;
password: string;
username: string;
}
/**
* /controllers/index.ts
*
* Base path: '/'
*/
export class Controller extends ControllerBase {
// define one or more middlewares
// for each route endpoint
public __use = [
express.urlencoded({ extended: true }),
];
/**
* [POST] /users endpoint
*/
@POST('/users')
public async new_user(req: express.Request, res: express.Response) {
const NEW_USER: INewUser = req.body;
// TODO ...
return res.status(200)
.send('Created new user: ' + JSON.stringify(
NEW_USER, null, 2
));
}
}
import * as express from 'express';
import { ControllerBase, GET, RequestErrorHandlerContext } from '@egodigital/express-controllers';
/**
* /controllers/index.ts
*
* Base path: '/'
*/
export class Controller extends ControllerBase {
// handle exceptions
public __error(context: RequestErrorHandlerContext) {
return context.response
.status(500)
.send('SERVER ERROR: ' + context.error);
}
/**
* [GET] / endpoint
*/
@GET()
public async index(req: express.Request, res: express.Response) {
// all request error, like that
// will be handled by
// '__error()' method
throw new Error('Test error!');
}
}
FAQs
Sets up controllers for Express framework.
The npm package @egodigital/express-controllers receives a total of 6 weekly downloads. As such, @egodigital/express-controllers popularity was classified as not popular.
We found that @egodigital/express-controllers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.