-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server):
createMiddlewareHandlerContext
(#17)
- Loading branch information
Showing
10 changed files
with
413 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { MiddlewareHandler } from "$fresh/server.ts"; | ||
|
||
interface Logger { | ||
info(...args: Array<unknown>): void; | ||
} | ||
|
||
export function createLoggerMiddleware(logger: Logger): MiddlewareHandler { | ||
return async (req, ctx) => { | ||
// Output logs in [koa-logger](https://github.com/koajs/logger) like format | ||
logger.info(`<-- ${req.method} ${new URL(req.url).pathname}`); | ||
const res = await ctx.next(); | ||
logger.info(`--> ${req.method} ${new URL(req.url).pathname} ${res.status}`); | ||
return res; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createLoggerMiddleware } from "./(_middlewares)/logger.ts"; | ||
|
||
export const handler = createLoggerMiddleware(console); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export * from "./components.ts"; | ||
export { createHandlerContext } from "./server.ts"; | ||
export { | ||
createHandlerContext, | ||
createMiddlewareHandlerContext, | ||
} from "./server.ts"; |
Oops, something went wrong.