woodland 20.2.6 → 20.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -12
- package/dist/cli.cjs +1 -1
- package/dist/woodland.cjs +1 -1
- package/dist/woodland.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -481,12 +481,9 @@ const app = woodland({
|
|
|
481
481
|
### Manual CORS Control (When Needed)
|
|
482
482
|
|
|
483
483
|
```javascript
|
|
484
|
-
//
|
|
485
|
-
app
|
|
486
|
-
|
|
487
|
-
res.header("access-control-allow-headers", "content-type"); // Restrict headers
|
|
488
|
-
res.header("access-control-max-age", "86400"); // Set cache duration
|
|
489
|
-
res.send("");
|
|
484
|
+
// Conditional CORS (disable automatic CORS, use manual)
|
|
485
|
+
const app = woodland({
|
|
486
|
+
origins: [] // Empty = no automatic CORS
|
|
490
487
|
});
|
|
491
488
|
|
|
492
489
|
// Dynamic origin validation (replaces automatic validation)
|
|
@@ -501,11 +498,6 @@ app.always((req, res, next) => {
|
|
|
501
498
|
next();
|
|
502
499
|
});
|
|
503
500
|
|
|
504
|
-
// Conditional CORS (disable automatic CORS, use manual)
|
|
505
|
-
const app = woodland({
|
|
506
|
-
origins: [] // Empty = no automatic CORS
|
|
507
|
-
});
|
|
508
|
-
|
|
509
501
|
app.always((req, res, next) => {
|
|
510
502
|
if (shouldAllowCORS(req)) {
|
|
511
503
|
res.header("access-control-allow-origin", req.headers.origin);
|
|
@@ -513,6 +505,14 @@ app.always((req, res, next) => {
|
|
|
513
505
|
}
|
|
514
506
|
next();
|
|
515
507
|
});
|
|
508
|
+
|
|
509
|
+
// Override automatic behavior for specific routes
|
|
510
|
+
app.options("/api/special", (req, res) => {
|
|
511
|
+
res.header("access-control-allow-methods", "GET,POST"); // Restrict methods
|
|
512
|
+
res.header("access-control-allow-headers", "content-type"); // Restrict headers
|
|
513
|
+
res.header("access-control-max-age", "86400"); // Set cache duration
|
|
514
|
+
res.send("");
|
|
515
|
+
});
|
|
516
516
|
```
|
|
517
517
|
|
|
518
518
|
**Most applications only need to configure `origins` and `corsExpose` - manual CORS handling is rarely necessary.**
|
|
@@ -748,7 +748,7 @@ new Woodland(config)
|
|
|
748
748
|
|
|
749
749
|
#### Utility Methods
|
|
750
750
|
|
|
751
|
-
- `always(path, ...middleware)` - All HTTP methods
|
|
751
|
+
- `always(path, ...middleware)` - All HTTP methods - executes before request HTTP method middleware
|
|
752
752
|
- `use(path, ...middleware, method)` - Generic middleware registration
|
|
753
753
|
- `files(root, folder)` - Static file serving
|
|
754
754
|
- `ignore(fn)` - Ignore middleware for `Allow` header
|
package/dist/cli.cjs
CHANGED
package/dist/woodland.cjs
CHANGED
package/dist/woodland.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @copyright 2025 Jason Mulligan <jason.mulligan@avoidwork.com>
|
|
5
5
|
* @license BSD-3-Clause
|
|
6
|
-
* @version 20.2.
|
|
6
|
+
* @version 20.2.7
|
|
7
7
|
*/
|
|
8
8
|
import {STATUS_CODES,METHODS}from'node:http';import {join,extname,resolve}from'node:path';import {EventEmitter}from'node:events';import {stat,readdir}from'node:fs/promises';import {readFileSync,createReadStream}from'node:fs';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 {coerce}from'tiny-coerce';import mimeDb from'mime-db';const __dirname$1 = fileURLToPath(new URL(".", import.meta.url));
|
|
9
9
|
const require = createRequire(import.meta.url);
|