diff --git a/dist/cli.cjs b/dist/cli.cjs index a1d432b..d99d1d3 100644 --- a/dist/cli.cjs +++ b/dist/cli.cjs @@ -4,7 +4,7 @@ * * @copyright 2024 Jason Mulligan * @license BSD-3-Clause - * @version 20.0.1 + * @version 20.0.2 */ 'use strict'; diff --git a/dist/woodland.cjs b/dist/woodland.cjs index 35191ed..1d5fd9c 100644 --- a/dist/woodland.cjs +++ b/dist/woodland.cjs @@ -3,7 +3,7 @@ * * @copyright 2024 Jason Mulligan * @license BSD-3-Clause - * @version 20.0.1 + * @version 20.0.2 */ 'use strict'; @@ -207,8 +207,10 @@ function next (req, res, middleware, immediate = false) { } else { res.error(getStatus(req, res)); } - } else { + } else if (typeof obj.value === FUNCTION) { obj.value(req, res, fn); + } else { + res.send(obj.value); } } else { res.error(getStatus(req, res)); diff --git a/dist/woodland.js b/dist/woodland.js index 6aa107a..cf5191f 100644 --- a/dist/woodland.js +++ b/dist/woodland.js @@ -3,7 +3,7 @@ * * @copyright 2024 Jason Mulligan * @license BSD-3-Clause - * @version 20.0.1 + * @version 20.0.2 */ import {STATUS_CODES,METHODS}from'node:http';import {join,extname}from'node:path';import {EventEmitter}from'node:events';import {stat,readdir}from'node:fs/promises';import {etag}from'tiny-etag';import {precise}from'precise';import {lru}from'tiny-lru';import {createRequire}from'node:module';import {fileURLToPath,URL}from'node:url';import {readFileSync,createReadStream}from'node:fs';import {coerce}from'tiny-coerce';import mimeDb from'mime-db';const __dirname$1 = fileURLToPath(new URL(".", import.meta.url)); const require = createRequire(import.meta.url); @@ -189,8 +189,10 @@ function next (req, res, middleware, immediate = false) { } else { res.error(getStatus(req, res)); } - } else { + } else if (typeof obj.value === FUNCTION) { obj.value(req, res, fn); + } else { + res.send(obj.value); } } else { res.error(getStatus(req, res)); diff --git a/package-lock.json b/package-lock.json index 6a524ae..120cbc4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "woodland", - "version": "20.0.1", + "version": "20.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "woodland", - "version": "20.0.1", + "version": "20.0.2", "license": "BSD-3-Clause", "dependencies": { "mime-db": "^1.53.0", diff --git a/package.json b/package.json index 23c5dae..6098992 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "woodland", - "version": "20.0.1", + "version": "20.0.2", "description": "Lightweight HTTP framework with automatic headers", "type": "module", "types": "types/woodland.d.ts", diff --git a/src/utility.js b/src/utility.js index 217c2b8..8d470e3 100644 --- a/src/utility.js +++ b/src/utility.js @@ -94,8 +94,10 @@ export function next (req, res, middleware, immediate = false) { } else { res.error(getStatus(req, res)); } - } else { + } else if (typeof obj.value === FUNCTION) { obj.value(req, res, fn); + } else { + res.send(obj.value); } } else { res.error(getStatus(req, res)); diff --git a/test/test.js b/test/test.js index 7fcc82e..4295054 100644 --- a/test/test.js +++ b/test/test.js @@ -81,6 +81,7 @@ router.use("/double-send", (req, res) => { res.send("Hello World 1!"); process.nextTick(() => res.send("Hello World 2!")); }); +router.get("/hi", "hello!"); // Methods router.connect("/methods", (req, res) => res.send("connect handler")); @@ -635,6 +636,13 @@ describe("Invalid Requests", function () { it("GET /last-error-invalid (502 / 'Faux Bad Gateway')", function () { return httptest({url: "http://localhost:8001/last-error-invalid"}) .expectStatus(502) + .end(); + }); + + it("GET /hi (200 / 'Primitive transmission')", function () { + return httptest({url: "http://localhost:8001/hi"}) + .expectStatus(200) + .expectBody(/hello!/) .end().then(() => server.close()); }); });