Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-joi-simple

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-joi-simple - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

src/RequestHandler.ts

4

package.json
{
"name": "express-joi-simple",
"version": "1.0.3",
"version": "1.0.4",
"description": "",

@@ -20,2 +20,3 @@ "main": "dist/index.js",

"dependencies": {
"body-parser": "^1.18.3",
"joi-express": "^1.0.3",

@@ -26,2 +27,3 @@ "swagger-json": "^1.3.4",

"devDependencies": {
"@types/body-parser": "^1.17.0",
"@types/express": "^4.16.0",

@@ -28,0 +30,0 @@ "@types/joi": "^13.4.2",

@@ -10,11 +10,12 @@ # Express + Joi + Swagger

## Example
## Minimal Working Example
```
import * as express from 'express';
import { router } from './router';
import * as joi from 'joi';
import { Doc, Validate } from 'express-joi-simple';
import * as BodyParser from 'body-parser';
import { Doc, Validate, RequestHandler } from 'express-joi-simple';
const app = express();
app.use(BodyParser.json());

@@ -24,7 +25,8 @@ const schema = {

test1: joi.string().required()
}
},
model: 'Register'
}
// Note middleware here
app.post('register',Validate(schema), (req: any, res: any) => {
app.post('register', Validate(schema), (req: any, res: any) => {
res.json({

@@ -35,3 +37,3 @@ message: 'register'

app.use('/login', router);
app.use(RequestHandler);

@@ -44,2 +46,3 @@ app.listen(3000, () => {

Use require instead of import for plain Javascript.
Use require instead of import for plain Javascript.
More complicated example you can find in example folder.

@@ -21,4 +21,9 @@

}
} else if (middleware.name === 'router') { // router middleware
} else if (middleware.name === 'router' && middleware.handle.stack) { // router middleware
middleware.handle.stack.forEach((handler: any) => {
if(!handler.route) {
return;
}
const { path, stack } = handler.route;

@@ -39,3 +44,3 @@ if (path) {

app.use('/', SwaggerUi.serve, SwaggerUi.setup(JSON.parse(swaggerDocument)));
app.use('/doc', SwaggerUi.serve, SwaggerUi.setup(JSON.parse(swaggerDocument)));
}
import * as express from 'express';
import { router } from './router';
import * as BodyParser from 'body-parser';
import * as joi from 'joi';
import { Doc, Validate } from '../index';
import { Doc, Validate, RequestHandler } from '../index';
const app = express();
app.use(BodyParser.json());
app.use(RequestHandler);
const schema = {
body: {
test1: joi.string().required()
}
},
model: 'Register'
}
app.post('register',Validate(schema), (req: any, res: any) => {
app.post('/register', Validate(schema), (req: any, res: any) => {
res.json({

@@ -22,4 +27,5 @@ message: 'register'

app.use(RequestHandler);
app.listen(3000, () => {
Doc(app);
})

@@ -6,7 +6,7 @@ import { Router } from 'express';

export const router: any = Router();
const schema = {
body: {
test1: joi.string().required()
}
},
model: 'Login'
}

@@ -13,0 +13,0 @@

export * from './Doc';
export * from './Validate';
export * from './RequestHandler';
import * as Joi from 'joi-express';
export function Validate(schema: any) {
return Joi(schema);
}
export const Validate = Joi;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc