From 579c08ab14eae18f1583657fe2993f715f3b5cf9 Mon Sep 17 00:00:00 2001 From: paku Date: Mon, 23 Dec 2024 15:58:14 +0900 Subject: [PATCH] Add docs directory --- LICENSE | 2 +- README.md | 11 ++------- docs/trailing-slash.md | 53 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 docs/trailing-slash.md diff --git a/LICENSE b/LICENSE index 6c00e23..f1274ad 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright 2024 skyizwhite +Copyright 2024 - present, skyizwhite Copyright 2021 - present, Yusuke Wada and Hono contributors 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: diff --git a/README.md b/README.md index 81b1402..9e50a94 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,17 @@ # lack-mw Middleware collection for [Lack](https://github.com/fukamachi/lack). - These middlewares were ported from [Hono](https://github.com/honojs/hono). ## Middlewares -- **trailing-slash** - Handles trailing slashes in URLs for GET requests. - If the requested resource isn’t found, it redirects to the correct URL accordingly. - - `*append-trailing-slash*` - Redirects to the URL **with** a trailing slash. - - `*trim-trailing-slash*` - Redirects to the URL **without** a trailing slash. +- [trailing-slash](/docs/trailing-slash.md) - Coming soon... ## License Licensed under the MIT License. -© 2024 skyizwhite +© 2024 - present, skyizwhite © 2021 - present, Yusuke Wada and Hono contributors \ No newline at end of file diff --git a/docs/trailing-slash.md b/docs/trailing-slash.md new file mode 100644 index 0000000..1439288 --- /dev/null +++ b/docs/trailing-slash.md @@ -0,0 +1,53 @@ +# trailing-slash middleware + +This middleware handles Trailing Slash in the URL on a GET request. + +`*append-trailing-slash*` redirects the URL to which it added the Trailing Slash if the content was not found. Also, `*trim-trailing-slash*` will remove the Trailing Slash. + +## Usage + +Example of redirecting a GET request of `/about/me` to `/about/me/`. + +```lisp +(defpackage #:app/main + (:use #:cl) + (:import-from #:ningle) + (:import-from #:lack) + (:import-from #:lack-mw + #:*append-trailing-slash*)) +(in-package #:app/main) + +(defparameter *raw-app* (make-instance 'ningle:app)) +(setf (ningle:route *raw-app* "/about/me/") + "With Trailing Slash") + +(defparameter *app* + (lack:builder + *append-trailing-slash* + *raw-app*)) +``` + +Example of redirecting a GET request of `/about/me/` to `/about/me`. + +```lisp +(defpackage #:app/main + (:use #:cl) + (:import-from #:ningle) + (:import-from #:lack) + (:import-from #:lack-mw + #:*trim-trailing-slash*)) +(in-package #:app/main) + +(defparameter *raw-app* (make-instance 'ningle:app)) +(setf (ningle:route *raw-app* "/about/me") + "Without Trailing Slash") + +(defparameter *app* + (lack:builder + *trim-trailing-slash* + *raw-app*)) +``` + +## Note + +It will be enabled when the request method is GET and the response status is `404`.