Comparing version 0.10.1 to 0.11.0-rc1
@@ -0,0 +0,0 @@ # Nodecaf Changelog |
module.exports = function getHTTPError(status, message){ | ||
let e = new Error(message); | ||
e.status = status; | ||
return e; | ||
}; | ||
class HTTPError extends Error { | ||
constructor(status, message) { | ||
super(message); | ||
this.status = status; | ||
this.name = 'HTTPError'; | ||
} | ||
} | ||
function anythingToError(thing){ | ||
if(thing instanceof HTTPError) | ||
return thing; | ||
if(thing instanceof Error) | ||
return new HTTPError(500, thing.message); | ||
if(typeof thing == 'object') | ||
return new HTTPError(500, JSON.stringify(thing)); | ||
return new HTTPError(500, String(thing)); | ||
} | ||
// This function is called when throw/rejection comes from route code (Except callbacks) | ||
// and from res.error() when calling it with an error | ||
function handleError(err, input){ | ||
input.res.failed = true; | ||
// Need to keep the original error stack and message for logging. | ||
input.res.err = err; | ||
let { log, res } = input; | ||
err = anythingToError(err); | ||
if(err.status < 500) | ||
return; | ||
log.error({ type: 'route', err: input.res.err }); | ||
if(!res.finished) | ||
res.status(err.status).end( | ||
/*istanbul ignore next */ | ||
process.env.NODE_ENV !== 'production' ? err.message : ''); | ||
} | ||
module.exports = { handleError, HTTPError }; |
const | ||
fs = require('fs'), | ||
cors = require('cors'), | ||
http = require('http'), | ||
https = require('https'), | ||
assert = require('assert'), | ||
Confort = require('confort'), | ||
{ METHODS } = require('http'), | ||
Logger = require('golog'), | ||
compression = require('compression'), | ||
cookieParser = require('cookie-parser'); | ||
const Logger = require('./logger'); | ||
const Router = require('./router'); | ||
const WSRouter = require('./ws'); | ||
const { startServer } = require('./http'); | ||
const API = require('./api'); | ||
@@ -39,3 +35,3 @@ const SHORT_TYPES = { | ||
this._api = opts.api || noop; | ||
this._apiSpec = opts.api || noop; | ||
this._startup = opts.startup || noop; | ||
@@ -48,3 +44,3 @@ this._shutdown = opts.shutdown || noop; | ||
assert(typeof this._api == 'function', | ||
assert(typeof this._apiSpec == 'function', | ||
new TypeError('API builder must be a function')); | ||
@@ -67,17 +63,5 @@ | ||
this._confort = new Confort(); | ||
this._router = new Router(this); | ||
this._wsRouter = new WSRouter(this); | ||
this._shouldParseBody = opts.shouldParseBody || typeof opts.shouldParseBody == 'undefined'; | ||
this._alwaysRebuildAPI = opts.alwaysRebuildAPI || false; | ||
// Generate HTTP verb shortcut route methods | ||
this._routeProxy = METHODS.reduce( (o, m) => | ||
({ ...o, [m.toLowerCase()]: this._router.addRoute.bind(this._router, m.toLowerCase()) }), {}); | ||
// Needed because it's not possible to call a function called 'delete' | ||
this._routeProxy.del = this._router.addRoute.bind(this._router, 'delete'); | ||
this._routeProxy.ws = this._wsRouter.set.bind(this._wsRouter); | ||
this.global = {}; | ||
this.conf = this._confort.object; | ||
@@ -90,3 +74,3 @@ this.running = false; | ||
if(!this._alwaysRebuildAPI) | ||
this._api(this._routeProxy); | ||
this._api = new API(this, this._apiSpec); | ||
} | ||
@@ -102,10 +86,5 @@ | ||
this.log = new Logger(this); | ||
this._ssl = this.conf.ssl ? { | ||
key: fs.readFileSync(this.conf.ssl.key), | ||
cert: fs.readFileSync(this.conf.ssl.cert) | ||
} : undefined; | ||
this.conf.port = this.conf.port || (this._ssl ? 443 : 80); | ||
if(this.conf.log) | ||
this.conf.log.defaults = { app: this._name }; | ||
this.log = new Logger(this.conf.log); | ||
} | ||
@@ -134,24 +113,16 @@ | ||
if(this._alwaysRebuildAPI){ | ||
this._router.clear(); | ||
this._api(this._routeProxy); | ||
} | ||
if(this._alwaysRebuildAPI) | ||
this._api = new API(this, this._apiSpec); | ||
if(!this._startup.noop) | ||
this.log.debug({ type: 'server' }, 'Starting up %s...', this._name); | ||
this.log.debug({ type: 'app' }, 'Starting up %s...', this._name); | ||
this.global = {}; | ||
await this._startup(this); | ||
let handler = this._router.handle.bind(this._router); | ||
this._server = this._ssl | ||
? https.createServer(this._ssl, handler) | ||
: http.createServer(handler); | ||
if(this.conf.port) | ||
await startServer.apply(this); | ||
else | ||
this.log.info({ type: 'app' }, '%s v%s has started', this._name, this._version); | ||
this._wsRouter.start(); | ||
await new Promise(done => this._server.listen(this.conf.port, done)); | ||
this.log.info({ type: 'server' }, | ||
'%s v%s is ready on port %s', this._name, this._version, this.conf.port); | ||
started(true); | ||
@@ -171,7 +142,7 @@ this.stopped = false; | ||
this._wsRouter.close(); | ||
if(this._server) | ||
await new Promise(done => this._server.close(done)); | ||
await new Promise(done => this._server.close(done)); | ||
await this._shutdown(this); | ||
delete this.global; | ||
@@ -184,2 +155,6 @@ this.log.info({ type: 'server' }, 'Stopped'); | ||
trigger(method, path, input){ | ||
return this._api.trigger(method, path, input); | ||
} | ||
async restart(conf){ | ||
@@ -186,0 +161,0 @@ await this.stop(); |
const { sign } = require('cookie-signature'); | ||
const cookie = require('cookie'); | ||
const { format } = require('util'); | ||
const { handleError } = require('./handle'); | ||
const getHTTPError = require('./error'); | ||
const { HTTPError, handleError } = require('./error'); | ||
@@ -69,3 +68,5 @@ const SHORT_CONTENT_TYPES = { | ||
error(status, message, ...args){ | ||
if(typeof status !== 'number') | ||
// If it's NOT a status, handle as an Error | ||
if(!Number.isInteger(status)) | ||
return handleError(status, this.input); | ||
@@ -81,4 +82,7 @@ | ||
this.status(status).end(message); | ||
// MAYBE we should do stackAborted on all sorts of errors | ||
this.stackAborted = true; | ||
return getHTTPError(status, message); | ||
return new HTTPError(status, message); | ||
}, | ||
@@ -120,5 +124,4 @@ | ||
// TODO 406 notAcceptable: | ||
// TODO 405 methodNotAllowed() | ||
// TODO 405 methodNotAllowed | ||
// TODO 408 Request Timeout | ||
@@ -125,0 +128,0 @@ // TODO 411 Length Required |
{ | ||
"name": "nodecaf", | ||
"version": "0.10.1", | ||
"version": "0.11.0-rc1", | ||
"description": "Nodecaf is a light framework for developing RESTful Apps in a quick and convenient manner.", | ||
@@ -47,2 +47,3 @@ "main": "lib/main.js", | ||
"cors": "^2.8.5", | ||
"golog": "^0.3.1", | ||
"path-to-regexp": "^6.1.0", | ||
@@ -55,5 +56,5 @@ "raw-body": "^2.4.1", | ||
"form-data": "^3.0.0", | ||
"muhb": "^3.0.3", | ||
"muhb": "^3.0.4", | ||
"toml": "^3.0.0" | ||
} | ||
} |
@@ -19,3 +19,2 @@ # [Nodecaf](https://gitlab.com/GCSBOSS/nodecaf) | ||
- [HTTPS capability](#https). | ||
- Functions to define [Websocket Routes](#websocket-routes). | ||
- Functions to [describe your API](#api-description) making your code the main | ||
@@ -211,14 +210,11 @@ source of truth. | ||
| error after headers sent | warn | An error happened inside a route after the headers were already sent | | ||
| route error | error | An error happened inside a route and was not caught | | ||
| fatal error | fatal | An error happened that crashed the server process | | ||
| route | error | An error happened inside a route and was not caught | | ||
| route | warn | next() used after stack has ended | | ||
| crash | fatal | An error happened that crashed the server process | | ||
| request | debug | A request has arrived | | ||
| response | debug | A response has been sent | | ||
| app | info | The application has started | | ||
| server | info | The server has started | | ||
| server | info | The server has stopped | | ||
| server | info | The server configuration has been reloaded | | ||
| websocket | debug | A new websocket connection happened | | ||
| websocket | debug | A message was received | | ||
| websocket | debug | A websocket connection was closed | | ||
| websocket | debug | Rejected a websocket connection to invalid path | | ||
| websocket | error | An error happened with a websocket connection | | ||
@@ -378,39 +374,2 @@ Additionally, you can filter log entries by level and type with the following | ||
## WebSocket Routes | ||
With nodecaf you can define paths to be accessible as WebSocket endpoints. | ||
In your api file use the `ws(path, events)` method with the folling arguments: | ||
1. `path`: where the websocket will be accessible | ||
2. `events`: object containing any of the following handlers: `connect`, `message`, `close`, `error`. | ||
```js | ||
module.exports = function({ post, get, del, head, patch, put, ws }){ | ||
// Regular api routes... | ||
// Websocket routes | ||
ws('/my-path-1', { | ||
connect: ({ client }) => console.log('NEW CLIENT'), | ||
message: ({ message, client }) => console.log('NEW MESSAGE'), | ||
close: ({ client }) => console.log('BYE CLIENT'), | ||
error: ({ err, client }) => console.log('I FEEL ODD') | ||
}); | ||
ws('/my-path-2', { | ||
connect: ({ client }) => console.log('NEW CLIENT 2'), | ||
message: ({ message, client }) => console.log('NEW MESSAGE 2'), | ||
close: ({ client }) => console.log('BYE CLIENT 2'), | ||
error: ({ err, client }) => console.log('I FEEL ODD 2') | ||
}); | ||
}; | ||
``` | ||
All handlers are optional for each websocket endpoint. | ||
Besides the ones showing, the following handler args are present in all ws handlers: `client`, `req`, `flash`, `conf`, `log`, `headers`, `query` and exposed vars. | ||
### Filter Requests by Mime-type | ||
@@ -417,0 +376,0 @@ |
filefoobar |
287
test/spec.js
@@ -36,4 +36,5 @@ const assert = require('assert'); | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post, del, patch }){ | ||
post('/foo', ({res}) => res.status(500).end() ); | ||
post('/foo', ({ res }) => res.status(500).end()); | ||
assert.strictEqual(typeof del, 'function'); | ||
@@ -52,2 +53,3 @@ assert.strictEqual(typeof patch, 'function'); | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ get }){ | ||
@@ -75,3 +77,3 @@ get('/bar', | ||
}); | ||
assert(!app._router.routes['/foobar']); | ||
assert(!app._api); | ||
}); | ||
@@ -97,3 +99,3 @@ | ||
it('Should start the http server on port 80', async () => { | ||
let app = new Nodecaf(); | ||
let app = new Nodecaf({ conf: { port: 80 } }); | ||
await app.start(); | ||
@@ -129,3 +131,3 @@ let { assert } = await base.get(''); | ||
it('Should rebuild the api when setup so [this.alwaysRebuildAPI]', async () => { | ||
let app = new Nodecaf({ alwaysRebuildAPI: true }); | ||
let app = new Nodecaf({ conf: { port: 80 }, alwaysRebuildAPI: true }); | ||
await app.start(); | ||
@@ -135,3 +137,3 @@ let { assert } = await base.get(''); | ||
await app.stop(); | ||
app._api = function({ get }){ | ||
app._apiSpec = function({ get }){ | ||
get('/foobar', ({ res }) => res.end()); | ||
@@ -150,3 +152,3 @@ }; | ||
it('Should stop the http server', async function(){ | ||
let app = new Nodecaf(); | ||
let app = new Nodecaf({ conf: { port: 80 } }); | ||
await app.start(); | ||
@@ -179,3 +181,3 @@ await app.stop(); | ||
this.timeout(3000); | ||
let app = new Nodecaf(); | ||
let app = new Nodecaf({ conf: { port: 80 } }); | ||
await app.start(); | ||
@@ -215,2 +217,43 @@ (await base.get('')).assert.status.is(404); | ||
describe('#trigger', () => { | ||
it('Should trigger route without http server', async () => { | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post }){ | ||
post('/foo', ({ res }) => res.status(202).end('Test')); | ||
post('/nores', ({ res }) => res.status(204).end()); | ||
} | ||
}); | ||
await app.start(); | ||
await app.trigger('post', '/nores'); | ||
let res = await app.trigger('post', '/foo'); | ||
assert.strictEqual(res.status, 202); | ||
assert.strictEqual(res.body, 'Test'); | ||
await app.stop(); | ||
}); | ||
it('Should default to response status to 200', async () => { | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post }){ | ||
post('/foo', ({ res }) => { | ||
res.setHeader('X-Test', 'Foo'); | ||
res.end(); | ||
}); | ||
post('/bar', ({ res }) => { | ||
res.getHeader('X-Test', 'Foo'); | ||
res.end(); | ||
}); | ||
} | ||
}); | ||
await app.start(); | ||
let r = await app.trigger('post', '/bar'); | ||
assert.strictEqual(r.status, 200); | ||
let res = await app.trigger('post', '/foo'); | ||
assert.strictEqual(res.headers['X-Test'], 'Foo'); | ||
await app.stop(); | ||
}); | ||
}); | ||
}); | ||
@@ -220,2 +263,38 @@ | ||
it('Should warn about next() after stack ended', async () => { | ||
let app = new Nodecaf({ | ||
api({ post }){ | ||
post('/foobaz', | ||
({ next }) => next(), | ||
({ next, res }) => { | ||
next(); | ||
res.end(); | ||
} | ||
); | ||
} | ||
}); | ||
await app.start(); | ||
let res = await app.trigger('post', '/foobaz'); | ||
assert.strictEqual(res.status, 200); | ||
await app.stop(); | ||
}); | ||
it('Should not call next function when stack was aborted', done => { | ||
let app = new Nodecaf({ | ||
api({ post }){ | ||
post('/unknown', ({ res, next }) => { | ||
res.error(500, 'test'); | ||
done(); | ||
next(); | ||
}, () => done()); | ||
} | ||
}); | ||
(async function(){ | ||
await app.start(); | ||
await app.trigger('post', '/unknown'); | ||
await app.stop(); | ||
})(); | ||
}); | ||
it('Should fail when receiving invalid route handlers', () => { | ||
@@ -234,2 +313,3 @@ new Nodecaf({ | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ get }){ | ||
@@ -252,2 +332,3 @@ get('/foo', function(obj){ | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ get }){ | ||
@@ -268,2 +349,3 @@ get('/fo/:o', Function.prototype); | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post }){ | ||
@@ -284,3 +366,3 @@ post('/foobar', ({ query, res, next }) => { | ||
it('Should output a 404 when no route is found for a given path', async () => { | ||
let app = new Nodecaf(); | ||
let app = new Nodecaf({ conf: { port: 80 } }); | ||
await app.start(); | ||
@@ -294,2 +376,3 @@ let { status } = await base.post('foobar'); | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ get }){ | ||
@@ -309,2 +392,3 @@ get('/foo', function({ res }){ | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ get }){ | ||
@@ -327,3 +411,3 @@ get('/foo', function({ res }){ | ||
let app = new Nodecaf({ | ||
conf: { cookie: { secret: 'OH YEAH' } }, | ||
conf: { port: 80, cookie: { secret: 'OH YEAH' } }, | ||
api({ get }){ | ||
@@ -353,2 +437,3 @@ | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ get }){ | ||
@@ -368,2 +453,3 @@ get('/foo', function({ res }){ | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ get }){ | ||
@@ -398,2 +484,3 @@ | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post }){ | ||
@@ -412,8 +499,6 @@ post('/bar', ({ body, res }) => { | ||
form.append('foobar', fs.createReadStream('./test/res/file.txt')); | ||
await new Promise(resolve => | ||
form.submit(LOCAL_HOST + '/bar/', (err, res) => { | ||
assert(res.headers['x-test'] == 'file.txt'); | ||
resolve(); | ||
}) | ||
); | ||
await new Promise(done => form.submit(LOCAL_HOST + '/bar/', (err, res) => { | ||
assert(res.headers['x-test'] == 'file.txt'); | ||
done(); | ||
})); | ||
@@ -425,2 +510,3 @@ await app.stop(); | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post }){ | ||
@@ -443,2 +529,3 @@ post('/foobar', ({ body, res }) => { | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post }){ | ||
@@ -461,2 +548,3 @@ post('/foobar', ({ body, res }) => { | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post }){ | ||
@@ -481,2 +569,3 @@ post('/foobar', ({ body, res }) => { | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post }){ | ||
@@ -501,2 +590,3 @@ post('/foobar', ({ body, res }) => { | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
shouldParseBody: false, | ||
@@ -526,2 +616,3 @@ api({ post }){ | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ get }){ | ||
@@ -546,2 +637,3 @@ get('/foo', function({ res }){ | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ get }){ | ||
@@ -571,2 +663,3 @@ get('/foo', function({ res }){ | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post }){ | ||
@@ -586,2 +679,3 @@ post('/unknown', () => { | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post }){ | ||
@@ -611,2 +705,3 @@ post('/known', ({ res }) => { | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post }){ | ||
@@ -626,2 +721,3 @@ post('/async', async () => { | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post }){ | ||
@@ -635,3 +731,3 @@ post('/known', ({ res }) => { | ||
await fs.readdir('.', function(){ | ||
res.error(new Error('errfoobar')); | ||
res.error({ a: 'b' }); | ||
}); | ||
@@ -658,20 +754,5 @@ }); | ||
it('Should log given event', async () => { | ||
let app = new Nodecaf({ | ||
api({ post }){ | ||
post('/foo', ({ log, res }) => { | ||
let entry = log.info('foobar'); | ||
assert.strictEqual(entry.msg, 'foobar'); | ||
res.end(); | ||
}); | ||
} | ||
}); | ||
await app.start(); | ||
await base.post('foo'); | ||
await app.stop(); | ||
}); | ||
it('Should not log filtered level and type', async () => { | ||
let app = new Nodecaf(); | ||
app.setup({ log: { type: 'test', level: 'info' } }); | ||
app.setup({ log: { only: 'test', level: 'info' } }); | ||
await app.start(); | ||
@@ -695,6 +776,6 @@ assert.strictEqual(app.log.debug({ type: 'test' }), false); | ||
describe('Regression', () => { | ||
const WebSocket = require('ws'); | ||
it('Should handle errors even when error event has no listeners', async () => { | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post }){ | ||
@@ -712,30 +793,2 @@ post('/bar', () => { | ||
it('Should not hang up connections when they have a query string', function(done){ | ||
let count = 0; | ||
let app = new Nodecaf({ | ||
api({ ws }){ | ||
ws('/foo', { | ||
connect: () => count++, | ||
async message({ message }){ | ||
assert.strictEqual('foobar', message); | ||
await app.stop(); | ||
count++; | ||
}, | ||
close(){ | ||
assert.strictEqual(count, 2); | ||
done(); | ||
} | ||
}); | ||
} | ||
}); | ||
(async function(){ | ||
await app.start(); | ||
const ws = new WebSocket('ws://localhost/foo?test=foobar'); | ||
ws.on('open', () => { | ||
ws.pong(); | ||
ws.send('foobar'); | ||
}); | ||
})(); | ||
}); | ||
it('Should not fail when attempting to close during startup', async () => { | ||
@@ -756,109 +809,7 @@ let app = new Nodecaf(); | ||
describe('WebSocket', function(){ | ||
const WebSocket = require('ws'); | ||
it('Should accept websocket connections and messages', function(done){ | ||
let count = 0; | ||
let app = new Nodecaf({ | ||
api({ ws }){ | ||
ws('/foo', { | ||
connect: () => count++, | ||
error: Function.prototype, | ||
async message({ message }){ | ||
assert.strictEqual('foobar', message); | ||
await app.stop(); | ||
count++; | ||
}, | ||
close(){ | ||
assert.strictEqual(count, 2); | ||
done(); | ||
} | ||
}); | ||
} | ||
}); | ||
(async function(){ | ||
await app.start(); | ||
const ws = new WebSocket('ws://localhost/foo'); | ||
ws.on('open', () => { | ||
ws.pong(); | ||
ws.send('foobar'); | ||
}); | ||
})(); | ||
}); | ||
it('Should reject connection to path that is not setup', function(done){ | ||
let app = new Nodecaf({ | ||
api: ({ ws }) => ws('/foo', {}) | ||
}); | ||
(async function(){ | ||
await app.start(); | ||
const ws = new WebSocket('ws://localhost/foobar'); | ||
ws.on('error', async () => { | ||
await app.stop(); | ||
done() | ||
}); | ||
})(); | ||
}); | ||
// it('Should properly handle client errors', function(done){ | ||
// let app = new Nodecaf(); | ||
// app.api(({ ws }) => { | ||
// ws('/foo', { error: done }); | ||
// }); | ||
// (async function(){ | ||
// await app.start(); | ||
// let ws = new WebSocket('ws://localhost/foo'); | ||
// ws.destroy(); | ||
// })(); | ||
// }); | ||
// it('Should not fail when client breaks connection during req body read', async () => { | ||
// let app = new Nodecaf(); | ||
// app.api(function({ post }){ | ||
// post('/foo', Function.prototype); | ||
// }); | ||
// await app.start(); | ||
// let req = require('http').request(LOCAL_HOST + '/foo', { method: 'POST' }); | ||
// req.write(JSON.stringify([...Array(2048)].keys())); | ||
// req.abort(); | ||
// await app.stop(); | ||
// }); | ||
}); | ||
describe('Other Features', function(){ | ||
const https = require('https'); | ||
it('Should start HTTPS server when specified', async function(){ | ||
let app = new Nodecaf({ | ||
conf: { | ||
ssl: { | ||
key: './test/res/key.pem', | ||
cert: './test/res/cert.pem' | ||
} | ||
}, | ||
api({ get }){ | ||
get('/foo', ({ res }) => res.end('bar') ); | ||
} | ||
}); | ||
await app.start(); | ||
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0; | ||
let res = await new Promise( resolve => | ||
https.get('https://localhost/foo', resolve) ); | ||
await new Promise( resolve => | ||
res.on('data', chunk => { | ||
assert.strictEqual(chunk.toString(), 'bar'); | ||
resolve(); | ||
}) ); | ||
await app.stop(); | ||
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 1; | ||
}); | ||
it('Should send permissive CORS headers when setup so [cors]', async () => { | ||
let app = new Nodecaf({ | ||
conf: { cors: true }, | ||
conf: { cors: true, port: 80 }, | ||
api({ get }){ | ||
@@ -879,2 +830,3 @@ get('/foobar', ({ res }) => res.end() ); | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post }){ | ||
@@ -886,4 +838,4 @@ post('/bar', ({ foo, res }) => { | ||
}); | ||
await app.start(); | ||
app.global.foo = 'foobar'; | ||
await app.start(); | ||
let { assert: { body } } = await base.post('bar'); | ||
@@ -896,3 +848,3 @@ body.exactly('foobar'); | ||
let app = new Nodecaf({ | ||
conf: { delay: 1500 }, | ||
conf: { delay: 1500, port: 80 }, | ||
api({ get }){ | ||
@@ -916,2 +868,3 @@ get('/foobar', ({ res }) => res.end()); | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post }){ | ||
@@ -934,2 +887,3 @@ let acc = this.accept([ 'urlencoded', 'text/html' ]); | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post }){ | ||
@@ -952,2 +906,3 @@ let acc = this.accept('text/html'); | ||
let app = new Nodecaf({ | ||
conf: { port: 80 }, | ||
api({ post }){ | ||
@@ -954,0 +909,0 @@ let acc = this.accept('text/html'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
5
2
85735
13
22
1289
1
465
+ Addedgolog@^0.3.1
+ Addedgolog@0.3.1(transitive)