mirror of
https://github.com/Wessel/kirbe.git
synced 2026-07-07 13:58:20 +02:00
Improvements
This commit is contained in:
36
test.js
36
test.js
@@ -1,28 +1,28 @@
|
||||
const w = require( 'wumpfetch' );
|
||||
const Kirbe = require( './index' );
|
||||
const w = require('wumpfetch');
|
||||
const Kirbe = require('./index');
|
||||
|
||||
const app = new Kirbe.Server();
|
||||
|
||||
app.use( ( req, res, next ) => req.url === '/middleware' ? res.status( 200 ).end() : next() );
|
||||
app.use((req, res, next) => req.url === '/middleware' ? res.status(200).end() : next());
|
||||
|
||||
app.post( '/parse', ( req, res ) => res.body({ 'sent': req.json() }).end() );
|
||||
app.route( 'GET', '/statusMsg', ( req, res ) => res.status( 200, 'kirbe won' ).end() );
|
||||
app.route( 'POST', ( req, res ) => res.body( 'Gotta catch em all!' ).end() );
|
||||
app.route( '/compatibility', ( req, res ) => {
|
||||
res.writeHead( 201, { 'test': 'hi' });
|
||||
res.end({ 'key': 'hi' });
|
||||
app.post('/parse', (req, res) => res.body({'sent': req.json()}).end());
|
||||
app.route('GET', '/statusMsg', (req, res) => res.status(200, 'kirbe won').end());
|
||||
app.route('POST', (req, res) => res.body('Gotta catch em all!').end());
|
||||
app.route('/compatibility', (req, res) => {
|
||||
res.writeHead(201, {'test': 'hi'});
|
||||
res.end({'key': 'hi'});
|
||||
});
|
||||
app.route( ( req, res ) => res.status( 404 ).body( 'Error: Content not found!' ).end() );
|
||||
app.route((req, res) => res.status(404).body('Error: Content not found!').end());
|
||||
|
||||
;( async() => {
|
||||
;(async() => {
|
||||
const res = [];
|
||||
res.push( await w( 'http://127.0.0.1:4040/bear' ).send() );
|
||||
res.push( await w( 'http://127.0.0.1:4040/statusMsg' ).send() );
|
||||
res.push( await w( 'http://127.0.0.1:4040/compatibility' ).send() );
|
||||
res.push( await w( 'http://127.0.0.1:4040/testExtension' ).send() );
|
||||
res.push( await w( 'http://127.0.0.1:4040/parse', 'POST' ).body({ 'hello': 123 }).send() );
|
||||
res.push(await w('http://127.0.0.1:4040/bear').send());
|
||||
res.push(await w('http://127.0.0.1:4040/statusMsg').send());
|
||||
res.push(await w('http://127.0.0.1:4040/compatibility').send());
|
||||
res.push(await w('http://127.0.0.1:4040/testExtension').send());
|
||||
res.push(await w('http://127.0.0.1:4040/parse', 'POST').body({'hello': 123}).send());
|
||||
|
||||
res.forEach( ( v, i ) => console.log( `${i}: ${v.statusCode}` ) );
|
||||
res.forEach((v, i) => console.log( `${i}: ${v.statusCode}`));
|
||||
})();
|
||||
|
||||
app.listen( 4040, '127.0.0.1' );
|
||||
app.listen(4040);
|
||||
Reference in New Issue
Block a user