0.2.3 • Published 2 years ago

navamid v0.2.3

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Navamid

Docs and courtesy: https://github.com/lukeed/navaid

Example

let mid = (req, res, next) => {
	req.date = new Date();		// Attach date on req object
	console.log("mid", req);
	// res.redirect("/books/1"); // Redirct to a route
	// next("no auth"); 		//Throw Error
	next(); 					// Call the next middleware
};

let auth = (req, res, next) => {
	console.log("auth required");
	next();
};

let router = Navamid("/" (uri, req, res) => console.log('404'), (err, req, res) => console.log(err));
// Attach routes
router
	.use(mid)
	.on("/", (req, res, next) => {
		console.log("~> /", req.date);
	})
	.on("/users/:username", auth, ({ params }) => {
		console.log("~> /users/:username", params);
	})
	.on("/books/*", auth, (req, res) => {
		console.log("~> /books/*", req);
	});
router.listen()

Difference from navaid

1. constructor navamid(base, on404, onError)

- Optional on404 and onError when there is any middleware errors.
- on404(uri, req, res)
- onError(err, req, res)

2. use(middleware(s))

- An array of global middlewares similar to express.js
- (req, res, next) - Middlware signature 

3. on(path, middleware(s))

- An array of middlewares to be executed for the path

4. listen(uri?, callback?)

- An optional callback to be called after starting the listener.

Req Object

{
	params: {},
	url: ""
}

Res Object

{
	run: (uri? :string),
	redirect: (uri: string, replace?: boolean);
}

Next

next(err?)
0.2.1

2 years ago

0.2.0

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

0.0.0

3 years ago