-
Notifications
You must be signed in to change notification settings - Fork 0
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
e1e512e
commit 11cbb54
Showing
3 changed files
with
86 additions
and
43 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
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 |
---|---|---|
@@ -1,68 +1,81 @@ | ||
import * as nv from './src'; | ||
|
||
|
||
|
||
class MiddlewareExecutionError extends nv.GenericError { | ||
public constructor( | ||
message: string | ||
) { | ||
super(message, 500); | ||
const testschema = new nv.Schema({ | ||
a: nv.String, | ||
c: { | ||
balls: nv.String | ||
} | ||
} | ||
}); | ||
|
||
|
||
const testschema2 = new nv.Schema({ | ||
a: nv.String, | ||
b: testschema | ||
}); | ||
|
||
|
||
|
||
console.log(await testschema2.validate({ a: '', b: { a: 'sdfsd', c:{o:'ck'} }})) | ||
|
||
// class MiddlewareExecutionError extends nv.GenericError { | ||
// public constructor( | ||
// message: string | ||
// ) { | ||
// super(message, 500); | ||
// } | ||
// } | ||
|
||
|
||
|
||
const server = new nv.Server(); | ||
const route = new nv.Route(server, '/contacts/email/check/:code'); | ||
|
||
class MW extends nv.GenericMiddleware { | ||
protected handler = async () => { | ||
console.log('Middleware executed'); | ||
return { 'a': 'test' } | ||
} | ||
} | ||
// class MW extends nv.GenericMiddleware { | ||
// protected handler = async () => { | ||
// console.log('Middleware executed'); | ||
// return { 'a': 'test' } | ||
// } | ||
// } | ||
|
||
|
||
const testschema = new nv.Schema({ | ||
a: nv.String | ||
}); | ||
|
||
nv.Binder(route, 'GET', { | ||
middleware: { | ||
test: MW, | ||
}, | ||
|
||
schemas: { | ||
input: { | ||
query: [testschema] | ||
body: [testschema2] | ||
} | ||
} | ||
}, async ({ | ||
middleware, | ||
url | ||
url, | ||
body | ||
}) => { | ||
console.log(url); | ||
console.log(body.b.c.balls); | ||
}); | ||
|
||
|
||
|
||
|
||
server.start(); | ||
// server.start(); | ||
|
||
|
||
|
||
const test = nv.register_api_route('localhost:8080', 'contacts/email/check/:code', 'GET', { | ||
input: { | ||
query: [testschema] | ||
} | ||
}); | ||
// const test = nv.register_api_route('localhost:8080', 'contacts/email/check/:code', 'GET', { | ||
// input: { | ||
// query: [testschema] | ||
// } | ||
// }); | ||
|
||
const res = await test({ | ||
route: { | ||
code: '1' | ||
}, | ||
query: { | ||
a: 'test' | ||
} | ||
}) | ||
// const res = await test({ | ||
// route: { | ||
// code: '1' | ||
// }, | ||
// query: { | ||
// a: 'test' | ||
// } | ||
// }) | ||
|
||
// console.log(res.success, res.error.message); | ||
// // console.log(res.success, res.error.message); | ||
|