-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50f99b3
commit 3c99090
Showing
10 changed files
with
200 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
## CHANGELOG | ||
Date format is DD/MM/YYYY | ||
|
||
# 0.1.0 (16th April 2017) | ||
## 0.2.0 (28/10/2017) | ||
* Add TypeScript support | ||
* Add new `fields` function for use with express-formidable | ||
|
||
## 0.1.0 (16/04/2017) | ||
* Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
exports.__esModule = true; | ||
var port = 3030; | ||
var express = require("express"); | ||
var Joi = require("joi"); | ||
var validation = require("../../express-joi-validation"); | ||
var app = express(); | ||
var validator = validation(); | ||
var headerSchema = Joi.object({ | ||
'host': Joi.string().required(), | ||
'user-agent': Joi.string().required() | ||
}); | ||
app.use(validator.headers(headerSchema)); | ||
app.get('/ping', function (req, res) { return res.end('pong'); }); | ||
app.listen(3030, function (err) { | ||
if (err) { | ||
throw err; | ||
} | ||
console.log("\napp started on " + port + "\n"); | ||
console.log("Try accessing http://localhost:" + port + "/users/1001 or http://localhost:" + port + "/users?name=dean to get some data.\n"); | ||
console.log("Now try access http://localhost:" + port + "/users?age=50. You should get an error complaining that your querystring is invalid."); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict' | ||
|
||
const port = 3030 | ||
|
||
import * as express from 'express' | ||
import * as Joi from 'joi' | ||
import * as validation from '../../express-joi-validation' | ||
|
||
const app = express() | ||
const validator = validation() | ||
|
||
const headerSchema = Joi.object({ | ||
'host': Joi.string().required(), | ||
'user-agent': Joi.string().required() | ||
}) | ||
|
||
app.use(validator.headers(headerSchema)) | ||
|
||
app.get('/ping', (req, res) => res.end('pong')) | ||
|
||
app.listen(port, (err: any) => { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
console.log(`\napp started on ${port}\n`) | ||
console.log(`Try accessing http://localhost:${port}/users/1001 or http://localhost:${port}/users?name=dean to get some data.\n`) | ||
console.log(`Now try access http://localhost:${port}/users?age=50. You should get an error complaining that your querystring is invalid.`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import * as Joi from 'joi'; | ||
import * as express from 'express' | ||
|
||
declare module 'express' { | ||
interface Request { | ||
originalBody: Array<any>|object|undefined | ||
originalQuery: object | ||
originalHeaders: object | ||
originalParams: object | ||
originalFields: object | ||
} | ||
} | ||
|
||
interface ExpressJoiConfig { | ||
joi?: typeof Joi | ||
statusCode?: number | ||
passError?: boolean | ||
} | ||
|
||
interface ExpressJoiContainerConfig { | ||
joi?: Joi.ValidationOptions | ||
statusCode?: number | ||
passError?: boolean | ||
} | ||
|
||
interface ExpressJoiInstance { | ||
body (schema: Joi.Schema, cfg?: ExpressJoiContainerConfig): express.RequestHandler | ||
query (schema: Joi.Schema, cfg?: ExpressJoiContainerConfig): express.RequestHandler | ||
params (schema: Joi.Schema, cfg?: ExpressJoiContainerConfig): express.RequestHandler | ||
headers (schema: Joi.Schema, cfg?: ExpressJoiContainerConfig): express.RequestHandler | ||
fields (schema: Joi.Schema, cfg?: ExpressJoiContainerConfig): express.RequestHandler | ||
} | ||
|
||
declare function validation (cfg? : ExpressJoiConfig): ExpressJoiInstance | ||
|
||
declare namespace validation {} | ||
|
||
export = validation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
x=1 | ||
|
||
while [ $x -le 10 ] | ||
do | ||
ab -n 1000 -c 100 -q http://127.0.0.1:8080/users?name=dean | grep -i "Requests per second" | ||
x=$(( $x + 1 )) | ||
sleep 5 | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"noImplicitAny": true, | ||
"removeComments": true, | ||
"preserveConstEnums": true, | ||
"sourceMap": true | ||
} | ||
} |