
Research
/Security News
Miasma Mini Shai-Hulud Hits ImmobiliareLabs npm Packages
Miasma Mini Shai-Hulud hits @immobiliarelabs Backstage plugins, targeting GitLab and LDAP auth packages on npm.
next-compose-router
Advanced tools
Create koa-router like handler for next.js.
$ npm install next-compose-router
Sometimes not all api need some validation operates, and as my Koa develop experiences, I prefer defining some apis' preprocessing separately and flexibly. So I write this toolkit to handle this
Create a next handler composed with multi middlewares
import {router} from "next-compose-router"
// usage
export default router(checkAuth, checkParams, (req, res) => {
// write handler here
res.send("success")
})
// others
export const FORBIDDEN = {message: "forbidden", status: 403}
export const BAD_REQUEST: IError = {message: "bad request", status: 400}
async function checkAuth(req, res, next) {
const token = req.headers.authorization
if (valid(token)) { // valid token here
await next()
} else {
throw FORBBIDEN
}
}
async function checkParams(req, res, next) {
const params = req.query
if (valid(params)) { // valid params here
await next()
} else {
throw BAD_REQUEST
}
}
Used to define self error handler
import {nextCompose} from "next-compose-router"
// default
const router = nextCompose((req, res, err) => {
throw err
})
const myRouter = nextCompose((req, res, {status, message}) => {
res.statusCode = status || 500
res.send({
error: {
status: status || 500,
message: status ? message : "internal error"
}
})
})
MIT
FAQs
create koa-router like next.js handler
The npm package next-compose-router receives a total of 3 weekly downloads. As such, next-compose-router popularity was classified as not popular.
We found that next-compose-router 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.

Research
/Security News
Miasma Mini Shai-Hulud hits @immobiliarelabs Backstage plugins, targeting GitLab and LDAP auth packages on npm.

Security News
Rolldown paused Rust React Compiler integration after a 5MB binary size increase raised concerns about shipping React-specific code to all Vite users.

Security News
/Research
Mini Shai-Hulud expands into the Go ecosystem after hitting LeoPlatform npm packages and targeting GitHub Actions workflows.