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.
@apoyo/express
Advanced tools
HTTP server utilities for express.
THIS PACKAGE IS NOT READY TO BE USED!
const getHealth = Request.reply(async () => {
return Http.Ok({
message: 'Everything is alright'
})
})
@apoyo/ioc
const listTodos = Request.reply(
TodoService.$findAll,
async (req, findTodos) => {
const todos = await findTodos()
return Http.Ok(todos)
})
@apoyo/decoders
const TodoCreateDto = ObjectDecoder.struct({
title: TextDecoder.string,
completed: BooleanDecoder.boolean
})
const createTodo = Request.reply(
TodoService.$createTodo,
(req, createTodo) => {
const dto = Request.validate(req.body, TodoCreateDto)
const saved = await createTodo(body)
return Http.Created(saved)
})
const todoRoutes = Route.group('/todos', {
children: [
Route.get('/', listTodos),
Route.get('/:id', getTodo),
Route.post('/', createTodo)
]
})
const routes = Route.group({
middlewares: [],
children: [
Route.get('/health', getHealth),
todoRoutes
]
})
// You can create error handlers easily: dependency injection works here as well!
const catchAll =
Request.catch(
[$logger],
async (err, logger) => {
logger.error('An internal error occured while executing HTTP request', err)
throw err
}
)
const routes = Route.group({
middlewares: [],
children: [
Route.get('/health', GetHealth),
todoRoutes
],
catch: [
// Add error catchers here!
catchAll
]
})
const catchCustomErrors = Request.catch((err) => {
if (err instanceof AccessException) {
throw Http.Forbidden({
message: err.message
})
}
// Re-throw non-http error to continue to the next error handler
throw err
})
const todoRoutes = Route.group('/todos', {
children: [
Route.get('/', ListTodos),
Route.get('/:id', GetTodo),
Route.post('/', CreateTodo)
],
catch: [
// They can also be added for a specific group of routes.
// This error handler will not be executed for /health for example.
catchCustomErrors
]
})
const $router = Express.createRouter(routes)
const $config = Injectable.of({
port: 3000
})
// Returning our app without starting it allows us to:
// - Easily combine multiple apps if necessary.
// - Test our endpoints with the "supertest" package.
const $app = Injectable.define([$router], (router) => {
const app = express()
// Configure your express app
...
app.use(router)
return app
})
// We start our application on the given port
const $server = Express.createServer($app, $config)
// This example has been simplified.
// As such, it does not listen to exit signals to gracefully exit the app.
// Usually, you should call `container.close` to close the resources that have been opened.
async function main () {
const container = Container.create()
await container.get($server)
}
main()
Container
instance to create the router middlewareconst app = express()
// Configure your express app
...
// Create new container for your application and register router
const $router = Express.createRouter(routes)
const container = Container.create()
const router = await container.get($router)
app.use(router)
...
// Start listening to your app
app.listen(3000)
Install express:
npm install express @types/express
Install peer dependencies:
npm install @apoyo/std @apoyo/decoders @apoyo/ioc
Install package:
npm install @apoyo/express
Please visit the documentation for more information.
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
Express utils
We found that @apoyo/express 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.