This repository has been archived by the owner on Dec 12, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 21
Refactor session handling #48
Open
interpretor
wants to merge
26
commits into
sidebase:main
Choose a base branch
from
interpretor:refactor-session-handling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
5138f30
Add rolling option
interpretor a34d5d8
Add saveUninitialized option
interpretor 4dc1d99
Update configuration example
interpretor 1a261b7
Avoid modifying input arguments
interpretor 99ac27f
Update configuration example
interpretor efc7dc2
Refactor saveUninitialized
interpretor 3629aa8
Add resave option
interpretor 8fbed4a
Update configuration example
interpretor 1cb0215
Use types for session options
interpretor dbd6bf4
Use types for session options
interpretor 46d9d1f
Use types for session options
interpretor 59b3b09
Merge branch 'add-saveuninitialized-option' into dev
interpretor 79eaf84
Merge branch 'add-resave-option' into dev
interpretor 9d39b4d
Refactor handling of modified sessions
interpretor 293ad80
Remove unnecessary interface declaration
interpretor 50cd690
Merge branch 'main' into refactor-session-handling
interpretor 0621975
Merge branch 'main' into refactor-session-handling
interpretor 477769f
Merge branch 'main' into refactor-session-handling
interpretor b98f67e
Merge branch 'main' into refactor-session-handling
interpretor 8238d43
Rename variable
interpretor 7b55c78
Add better explanation to saveUninitialized
interpretor 90d68bc
Provide better naming
interpretor 65a5f34
Merge branch 'refactor-session-handling' of github.com:interpretor/nu…
interpretor 0b5b25a
Provide better explanation for resave
interpretor 0418846
Fix indentation and comma
interpretor dd4b7b3
Merge branch 'main' into refactor-session-handling
interpretor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,14 @@ | ||
import type { ServerResponse } from 'node:http' | ||
|
||
type MiddleWare = () => Promise<void> | ||
|
||
// Proxy res.end() to get a callback at the end of all event handlers | ||
export const resEndProxy = (res: ServerResponse, middleWare: MiddleWare) => { | ||
const end = res.end | ||
|
||
// @ts-ignore Replacing res.end() will lead to type checking error | ||
res.end = async (chunk: any, encoding: BufferEncoding) => { | ||
await middleWare() | ||
return end.call(res, chunk, encoding) as ServerResponse | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need to typecast it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overwriting standard node js methods is obviously not recommended. Is there a better way doing that?
res.end
can be async, since it is expected to returnthis
according to the docs I don't think it's being awaited. Was it at least tested with long timeouts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that there is no alternative, as already mentioned in #41. There is no hook at the end of all event handlers, and no event that fires just before sending the response.
res.end
returns always aServerResponse
, and here it returns aPromise<ServerResponse>
. Also there are multiple overloads, andres.end
also accepts a callback. In express session this leads to problems, so they decided to ditch the callback, as it is very rarely used.res.end
being async, but it works perfectly. I tested with long timeouts with various conditions, so it must be awaited, but I didn't check it in the node source code.