UNPKG

oneside

Version:

OneSide is a HTTP Node Server for websites.

31 lines (30 loc) 786 B
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); exports.Next = void 0; class Next { constructor(req, res, middlewares, notFoundEndpoint) { this.req = req; this.res = res; this.middlewares = middlewares; this.notFoundEndpoint = notFoundEndpoint; this.i = 0; this.ended = false; } ok() { if (!this.ended && this.middlewares[this.i + 1]) { this.i++; this.middlewares[this.i](this.req, this.res, this); } } notFound() { if (!this.ended) { if (this.notFoundEndpoint) { this.notFoundEndpoint(this.req, this.res, this); } else { this.res.setHeader('Content-Type', 'text/html'); this.res.status(404).send(`<p>404 not found</p>`); } } } } exports.Next = Next;