Comparing version 0.7.3 to 0.7.4
@@ -8,2 +8,10 @@ # Nodecaf Changelog | ||
## [v0.7.4] - 2019-07-22 | ||
### Added | ||
- option to disable all request body parsing | ||
### Removed | ||
- ability to set up app name and version through config files | ||
## [v0.7.3] - 2019-07-16 | ||
@@ -175,1 +183,2 @@ | ||
[v0.7.3]: https://gitlab.com/GCSBOSS/nodecaf/-/tags/v0.7.3 | ||
[v0.7.4]: https://gitlab.com/GCSBOSS/nodecaf/-/tags/v0.7.4 |
@@ -38,2 +38,6 @@ const fs = require('fs'); | ||
this.express = noAPI; | ||
this.name = 'express'; | ||
this.version = '0.0.0'; | ||
this.shouldParseBody = true; | ||
this.setup(settings); | ||
@@ -58,5 +62,2 @@ | ||
this.name = this.settings.name || 'express'; | ||
this.version = this.settings.version || '0.0.0'; | ||
// Setup logger. | ||
@@ -63,0 +64,0 @@ setupLogger.bind(this)(this.settings.log); |
@@ -47,2 +47,4 @@ const os = require('os'); | ||
async function parse(req, res, next){ | ||
// this => app | ||
req.body = ''; | ||
@@ -52,2 +54,5 @@ if(!req.hasBody) | ||
if(!this.shouldParseBody) | ||
return next(); | ||
if(req.contentType in parsers) | ||
@@ -123,3 +128,3 @@ return parsers[req.contentType](req, res, next); | ||
// Physically add the adapted route to Express. | ||
this.express[method](path, accept, parse, ...aRoutes); | ||
this.express[method](path, accept, parse.bind(this), ...aRoutes); | ||
return { desc: Function.prototype }; | ||
@@ -126,0 +131,0 @@ }, |
{ | ||
"name": "nodecaf", | ||
"version": "0.7.3", | ||
"version": "0.7.4", | ||
"description": "Nodecaf is an Express framework for developing REST APIs in a quick and convenient manner.", | ||
@@ -52,3 +52,3 @@ "main": "lib/main.js", | ||
"form-data": "^2.5.0", | ||
"muhb": "^0.1.1", | ||
"muhb": "^1.0.0", | ||
"swagger-parser": "^8.0.0", | ||
@@ -55,0 +55,0 @@ "tempper": "^0.1.1", |
171
test/spec.js
@@ -56,5 +56,7 @@ //const wtf = require('wtfnode'); | ||
const { get, root } = require('muhb'); | ||
let base = root(LOCAL_HOST); | ||
describe('AppServer', () => { | ||
const AppServer = require('../lib/app-server'); | ||
const { get, post } = require('muhb'); | ||
@@ -75,4 +77,4 @@ describe('constructor', () => { | ||
await app.start(); | ||
let { status } = await get(LOCAL_HOST); | ||
assert.strictEqual(status, 404); | ||
let { assert } = await base.get(''); | ||
assert.status.is(404); | ||
await app.stop(); | ||
@@ -84,4 +86,4 @@ }); | ||
await app.start(); | ||
let { status } = await get('http://127.0.0.1:8765/'); | ||
assert.strictEqual(status, 404); | ||
let { assert } = await get('http://127.0.0.1:8765/'); | ||
assert.status.is(404); | ||
await app.stop(); | ||
@@ -125,4 +127,4 @@ }); | ||
await app.start(); | ||
let { status } = await post(LOCAL_HOST + 'foo'); | ||
assert.strictEqual(status, 500); | ||
let { assert: { status } } = await base.post('foo'); | ||
status.is(500); | ||
await app.stop(); | ||
@@ -140,4 +142,4 @@ }); | ||
await app.start(); | ||
let { body } = await get(LOCAL_HOST + 'bar'); | ||
assert.strictEqual(body, 'bar'); | ||
let { assert: { body } } = await base.get('bar'); | ||
body.exactly('bar'); | ||
await app.stop(); | ||
@@ -157,4 +159,4 @@ }); | ||
await app.start(); | ||
let { body } = await post(LOCAL_HOST + 'bar'); | ||
assert.strictEqual(body, 'foobar'); | ||
let { assert: { body } } = await base.post('bar'); | ||
body.exactly('foobar'); | ||
await app.stop(); | ||
@@ -172,3 +174,3 @@ }); | ||
try{ | ||
await get(LOCAL_HOST); | ||
await base.get(''); | ||
} | ||
@@ -204,7 +206,5 @@ catch(e){ | ||
await app.start(); | ||
let { status } = await get(LOCAL_HOST); | ||
assert.strictEqual(status, 404); | ||
(await base.get('')).assert.status.is(404); | ||
await app.restart(); | ||
let { status: s } = await get(LOCAL_HOST); | ||
assert.strictEqual(s, 404); | ||
(await base.get('')).assert.status.is(404); | ||
await app.stop(); | ||
@@ -226,9 +226,9 @@ }); | ||
await app.start(); | ||
let { body, status } = await post( | ||
LOCAL_HOST + 'foo', | ||
let { assert: { body, status } } = await base.post( | ||
'foo', | ||
{ 'Content-Type': 'application/json' }, | ||
'{"foo":"bar"}' | ||
); | ||
assert.strictEqual(status, 400); | ||
assert(/Unsupported/.test(body)); | ||
status.is(400); | ||
body.match(/Unsupported/); | ||
await app.stop(); | ||
@@ -244,9 +244,9 @@ }); | ||
await app.start(); | ||
let { body, status } = await post( | ||
LOCAL_HOST + 'foo', | ||
let { assert } = await base.post( | ||
'foo', | ||
{ '--no-auto': true, 'Content-Length': 13 }, | ||
'{"foo":"bar"}' | ||
); | ||
assert.strictEqual(status, 400); | ||
assert(/Missing/.test(body)); | ||
assert.status.is(400); | ||
assert.body.match(/Missing/); | ||
await app.stop(); | ||
@@ -262,8 +262,8 @@ }); | ||
await app.start(); | ||
let { status } = await post( | ||
LOCAL_HOST + 'foo', | ||
let { assert } = await base.post( | ||
'foo', | ||
{ 'Content-Type': 'text/html' }, | ||
'{"foo":"bar"}' | ||
); | ||
assert.strictEqual(status, 200); | ||
assert.status.is(200); | ||
await app.stop(); | ||
@@ -279,7 +279,4 @@ }); | ||
await app.start(); | ||
let { status } = await post( | ||
LOCAL_HOST + 'foo', | ||
{ '--no-auto': true } | ||
); | ||
assert.strictEqual(status, 200); | ||
let { assert } = await base.post('foo', { '--no-auto': true }); | ||
assert.status.is(200); | ||
await app.stop(); | ||
@@ -290,3 +287,3 @@ }); | ||
describe('::setup', () => { | ||
describe('#setup', () => { | ||
@@ -313,3 +310,2 @@ it('Should apply settings on top of existing one', () => { | ||
const AppServer = require('../lib/app-server'); | ||
const { post, get } = require('muhb'); | ||
@@ -343,4 +339,3 @@ const { EventEmitter } = require('events'); | ||
await app.start(); | ||
let { status } = await get(LOCAL_HOST + 'foo'); | ||
assert.strictEqual(status, 200); | ||
(await base.get('foo')).assert.status.is(200); | ||
await app.stop(); | ||
@@ -383,8 +378,8 @@ }); | ||
await app.start(); | ||
let { status } = await post( | ||
LOCAL_HOST + 'foobar', | ||
let { assert: { status } } = await base.post( | ||
'foobar', | ||
{ 'Content-Type': 'application/json' }, | ||
JSON.stringify({foo: 'bar'}) | ||
); | ||
assert.strictEqual(status, 200); | ||
status.is(200); | ||
await app.stop(); | ||
@@ -402,8 +397,8 @@ }); | ||
await app.start(); | ||
let { status } = await post( | ||
LOCAL_HOST + 'foobar', | ||
let { assert: { status } } = await base.post( | ||
'foobar', | ||
{ '--no-auto': true, 'Content-Length': 13 }, | ||
JSON.stringify({foo: 'bar'}) | ||
); | ||
assert.strictEqual(status, 200); | ||
status.is(200); | ||
await app.stop(); | ||
@@ -421,11 +416,30 @@ }); | ||
await app.start(); | ||
let { status } = await post( | ||
LOCAL_HOST + 'foobar', | ||
let { assert: { status } } = await base.post( | ||
'foobar', | ||
{ 'Content-Type': 'application/x-www-form-urlencoded' }, | ||
'foo=bar' | ||
); | ||
assert.strictEqual(status, 200); | ||
status.is(200); | ||
await app.stop(); | ||
}); | ||
it('Should not parse request body when setup so', async () => { | ||
let app = new AppServer(); | ||
app.shouldParseBody = false; | ||
app.api(function({ post }){ | ||
post('/foobar', ({ body, res }) => { | ||
assert(!body); | ||
res.end(); | ||
}); | ||
}); | ||
await app.start(); | ||
let { assert: { status } } = await base.post( | ||
'foobar', | ||
{ 'Content-Type': 'application/x-www-form-urlencoded' }, | ||
'foo=bar' | ||
); | ||
status.is(200); | ||
await app.stop(); | ||
}); | ||
it('Should parse URL query string', async () => { | ||
@@ -440,3 +454,3 @@ let app = new AppServer(); | ||
await app.start(); | ||
let { status } = await post(LOCAL_HOST + 'foobar?foo=bar'); | ||
let { status } = await base.post('foobar?foo=bar'); | ||
assert.strictEqual(status, 200); | ||
@@ -450,3 +464,3 @@ await app.stop(); | ||
await app.start(); | ||
let { status, body } = await post(LOCAL_HOST + 'foobar'); | ||
let { status, body } = await base.post('foobar'); | ||
assert.strictEqual(status, 404); | ||
@@ -465,3 +479,3 @@ assert.strictEqual(body, ''); | ||
await app.start(); | ||
let { body } = await post(LOCAL_HOST + 'foobar'); | ||
let { body } = await base.post('foobar'); | ||
assert.doesNotThrow( () => JSON.parse(body) ); | ||
@@ -482,4 +496,4 @@ await app.stop(); | ||
await app.start(); | ||
let { body, status } = await post( | ||
LOCAL_HOST + 'foo', | ||
let { body, status } = await base.post( | ||
'foo', | ||
{ 'Content-Type': 'application/json' }, | ||
@@ -501,4 +515,4 @@ '{"foo":"bar"}' | ||
await app.start(); | ||
let { status } = await post( | ||
LOCAL_HOST + 'foo', | ||
let { status } = await base.post( | ||
'foo', | ||
{ 'Content-Type': 'text/html' }, | ||
@@ -518,4 +532,4 @@ '{"foo":"bar"}' | ||
await app.start(); | ||
let { status } = await post( | ||
LOCAL_HOST + 'foo', | ||
let { status } = await base.post( | ||
'foo', | ||
{ '--no-auto': true }, | ||
@@ -534,3 +548,2 @@ '{"foo":"bar"}' | ||
const { run, AppServer } = require('../lib/main'); | ||
const { get } = require('muhb'); | ||
@@ -556,3 +569,3 @@ it('Should fail when non function is sent', async () => { | ||
} }); | ||
let { body } = await get(LOCAL_HOST + 'bar'); | ||
let { body } = await base.get('bar'); | ||
assert.strictEqual(body, 'foo'); | ||
@@ -571,3 +584,3 @@ await app.stop(); | ||
}, confPath: 'test/res/conf.toml' }); | ||
let { body } = await get(LOCAL_HOST + 'bar'); | ||
let { body } = await base.get('bar'); | ||
assert.strictEqual(body, 'value'); | ||
@@ -614,3 +627,2 @@ await app.stop(); | ||
const AppServer = require('../lib/app-server'); | ||
const { post } = require('muhb'); | ||
const fs = require('fs'); | ||
@@ -626,3 +638,3 @@ | ||
await app.start(); | ||
let { status: status } = await post(LOCAL_HOST + 'unknown'); | ||
let { status: status } = await base.post('unknown'); | ||
assert.strictEqual(status, 500); | ||
@@ -643,5 +655,5 @@ await app.stop(); | ||
await app.start(); | ||
let { status } = await post(LOCAL_HOST + 'known'); | ||
let { status } = await base.post('known'); | ||
assert.strictEqual(status, 404); | ||
let { status: s2 } = await post(LOCAL_HOST + 'unknown'); | ||
let { status: s2 } = await base.post('unknown'); | ||
assert.strictEqual(s2, 500); | ||
@@ -670,7 +682,7 @@ await app.stop(); | ||
await app.start(); | ||
let { status } = await post(LOCAL_HOST + 'known'); | ||
let { status } = await base.post('known'); | ||
assert.strictEqual(status, 404); | ||
let { status: s2 } = await post(LOCAL_HOST + 'unknown'); | ||
let { status: s2 } = await base.post('unknown'); | ||
assert.strictEqual(s2, 500); | ||
let { status: s3 } = await post(LOCAL_HOST + 'unknown/object'); | ||
let { status: s3 } = await base.post('unknown/object'); | ||
assert.strictEqual(s3, 500); | ||
@@ -696,5 +708,5 @@ await app.stop(); | ||
await app.start(); | ||
let { status } = await post(LOCAL_HOST + 'known'); | ||
let { status } = await base.post('known'); | ||
assert.strictEqual(status, 500); | ||
let { status: s2 } = await post(LOCAL_HOST + 'unknown'); | ||
let { status: s2 } = await base.post('unknown'); | ||
assert.strictEqual(s2, 404); | ||
@@ -716,3 +728,3 @@ assert.strictEqual(count, 2); | ||
await app.start(); | ||
let { status } = await post(LOCAL_HOST + 'unknown'); | ||
let { status } = await base.post('unknown'); | ||
assert.strictEqual(status, 401); | ||
@@ -726,3 +738,2 @@ await app.stop(); | ||
const { run, AppServer } = require('../lib/main'); | ||
const { post } = require('muhb'); | ||
const fs = require('fs'); | ||
@@ -748,3 +759,3 @@ const os = require('os'); | ||
await app.start(); | ||
await post(LOCAL_HOST + 'foo'); | ||
await base.post('foo'); | ||
let data = await fs.promises.readFile(file, 'utf-8'); | ||
@@ -766,3 +777,3 @@ assert(data.indexOf('logfile') > 0); | ||
await app.start(); | ||
await post(LOCAL_HOST + 'foo'); | ||
await base.post('foo'); | ||
let data = await fs.promises.readFile(file, 'utf-8'); | ||
@@ -781,3 +792,3 @@ assert(data.indexOf('logstream') > 0); | ||
await app.start(); | ||
await post(LOCAL_HOST + 'foo'); | ||
await base.post('foo'); | ||
let data = await fs.promises.readFile(file, 'utf-8'); | ||
@@ -796,3 +807,3 @@ assert(data.indexOf('POST') > 0); | ||
await app.start(); | ||
await post(LOCAL_HOST + 'foo'); | ||
await base.post('foo'); | ||
let data = await fs.promises.readFile(file, 'utf-8'); | ||
@@ -820,3 +831,2 @@ assert(data.indexOf('Oh yeah') > 0); | ||
const { accept } = require('../lib/parse-types'); | ||
const { post } = require('muhb'); | ||
@@ -835,3 +845,3 @@ it('Should not interfere with working API code', async () => { | ||
await app.start(); | ||
let { body } = await post(LOCAL_HOST + 'foo/baz'); | ||
let { body } = await base.post('foo/baz'); | ||
assert.strictEqual(body, 'OK'); | ||
@@ -946,3 +956,2 @@ await app.stop(); | ||
const AppServer = require('../lib/app-server'); | ||
const { post } = require('muhb'); | ||
@@ -957,3 +966,3 @@ it('Should handle errors even when error event has no listeners', async () => { | ||
await app.start(); | ||
let { status } = await post(LOCAL_HOST + 'bar'); | ||
let { status } = await base.post('bar'); | ||
assert.strictEqual(status, 500); | ||
@@ -973,5 +982,5 @@ await app.stop(); | ||
let r1 = (await post(LOCAL_HOST + 'bar')).body; | ||
let r2 = (await post(LOCAL_HOST + 'bar')).body; | ||
let r3 = (await post(LOCAL_HOST + 'bar')).body; | ||
let r1 = (await base.post('bar')).body; | ||
let r2 = (await base.post('bar')).body; | ||
let r3 = (await base.post('bar')).body; | ||
assert(r1 == r2 && r2 == r3 && r3 == 'errfoobar'); | ||
@@ -992,3 +1001,3 @@ | ||
let m = (await post(LOCAL_HOST + 'bar')).body; | ||
let m = (await base.post('bar')).body; | ||
assert.strictEqual(m, 'NotFound'); | ||
@@ -1012,3 +1021,3 @@ | ||
await app.start(); | ||
await post(LOCAL_HOST + 'bar'); | ||
await base.post('bar'); | ||
await app.stop(); | ||
@@ -1015,0 +1024,0 @@ assert(gotHere); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
95265
1656