Skip to content

Commit

Permalink
Re-enabling primitives as routes
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Aug 29, 2024
1 parent 877a162 commit 028a5c6
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 20.0.1
* @version 20.0.2
*/
'use strict';

Expand Down
6 changes: 4 additions & 2 deletions dist/woodland.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 20.0.1
* @version 20.0.2
*/
'use strict';

Expand Down Expand Up @@ -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));
Expand Down
6 changes: 4 additions & 2 deletions dist/woodland.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com>
* @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);
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 3 additions & 1 deletion src/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
8 changes: 8 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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());
});
});

0 comments on commit 028a5c6

Please sign in to comment.