diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5d12634 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..79d0efb --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.DS_Store +Thumbs.db +npm/ +coverage diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..09cf720 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "denoland.vscode-deno" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..45dc064 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,18 @@ +{ + "deno.enable": true, + "deno.lint": true, + "deno.codeLens.test": true, + "editor.defaultFormatter": "denoland.vscode-deno", + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.fixAll": true + }, + "deno.inlayHints.enumMemberValues.enabled": false, + "deno.inlayHints.functionLikeReturnTypes.enabled": false, + "deno.inlayHints.parameterTypes.enabled": false, + "deno.inlayHints.propertyDeclarationTypes.enabled": false, + "deno.inlayHints.variableTypes.suppressWhenTypeMatchesName": false, + "deno.inlayHints.variableTypes.enabled": false, + "deno.inlayHints.parameterNames.enabled": "none", + "deno.inlayHints.parameterNames.suppressWhenArgumentMatchesName": false +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..797920f --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +MIT License + +Copyright (c) 2023 httpland + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e6fbde8 --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# http-middleware + +HTTP middleware specification + +## What + +Define standard HTTP middleware specifications. This is intended to increase the +interoperability of the HTTP library's own middleware. + +It consists only of the web standards stack and is compatible with many +Browsers. + +## Interface + +Middleware interfaces can be defined in TypeScript as follows: + +```ts +interface Middleware { + (request: Request, next: Handler): Response | Promise; +} + +interface Handler { + (request: Request): Response | Promise; +} +``` + +## Features + +`Middleware` has the following features: + +- Compatible with `Handler`. + + `Handler` is a powerful interface for handling HTTP requests. The `Middleware` + is purely an extension and compatibility with `Handler`. + +- It can access to the `Request`. +- It can access the next handler. +- It can call the next handler. +- It can choose not to call the next handler. +- It can access the next handler's return value (`Response`). +- It can return `Response`. + +## License + +Copyright © 2023-present [httpland](https://github.com/httpland). + +Released under the [MIT](./LICENSE) license diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..567ef77 --- /dev/null +++ b/deno.json @@ -0,0 +1,27 @@ +{ + "tasks": { + "test": "deno test --doc", + "coverage": "deno coverage", + "build:npm": "deno run -A _tools/build_npm.ts" + }, + "fmt": { + "files": { + "exclude": ["CHANGELOG.md", "CODE_OF_CONDUCT.md"] + } + }, + "lint": { + "files": { + "exclude": ["CHANGELOG.md", "CODE_OF_CONDUCT.md"] + } + }, + "test": { + "files": { + "exclude": ["CHANGELOG.md", "CODE_OF_CONDUCT.md"] + } + }, + "compilerOptions": { + "noImplicitReturns": true, + "noImplicitOverride": true, + "noUncheckedIndexedAccess": true + } +}