New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Core: Replace express
with connect
#27045
base: next
Are you sure you want to change the base?
Conversation
Migrates away from express, instead using connect and the underlying node server directly. Both express and connect support the same middleware structure, which means most middleware packages work for both and have remained the same in this change. A few notes: - Express' router has been replaced by basic connect mount points (though the two are not equivalent exactly) - Express static has been replaced by sirv This trims a large sub-tree of dependencies from our packages which express was pulling in. We in fact use very little of the functionality express gives us, only really making use of the connect-style API anyway.
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 66d27f8. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
express
with connect
@@ -114,7 +114,7 @@ export const bail: WebpackBuilder['bail'] = async () => { | |||
const starter: StarterFunction = async function* starterGeneratorFn({ | |||
startTime, | |||
options, | |||
router, | |||
app, |
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.
Is there any way we can make this backwards compatible?
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 may be difficult since router
is basically the {get, post}
shape etc
maybe we could have a wrapper around the connect server which does these 🤔
something like:
const router = {
get(path, callback) {
app(path, (req, res, next) => {
// check the method is `GET` here and do nothing if it isn't
callback(req, res, next);
});
},
// ...
};
although keep in mind path
would be treated as a prefix rather than a route pattern (i.e. /foo
would capture /foo/bar
, and there's no such thing as /foo/:someParam
anymore, i.e. params).
@ndelangen got the tests passing for you FYI 👍 |
Migrates away from express, instead using connect and the underlying node server directly.
Both express and connect support the same middleware structure, which means most middleware packages work for both and have remained the same in this change.
A few notes:
This trims a large sub-tree of dependencies from our packages which express was pulling in. We in fact use very little of the functionality express gives us, only really making use of the connect-style API anyway.
I've left a few TODOs around the code while this is a draft to help guide reviewers until it is done (if ever)
Express static
Replacing this with
sirv
means it isn't as simple as mounting real paths at aliased paths, since sirv takes a single directory as its source.Due to this, we give it
process.cwd()
and mutatereq.url
to be the path relative to cwd.Express router
We previously exposed
router
to managers and a few other middleware factories. These now consume anapp
(a connectServer
).A few main differences between the "full fat" router and basic mounts:
app('/foo', fn)
would match/foo/bar
too, andfn
would receive{url: '/bar'}
(relative to the mount point)Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
Run the sandbox and observe that it all works as expected
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
Make sure this PR contains one of the labels below:
Available labels
bug
: Internal changes that fixes incorrect behavior.maintenance
: User-facing maintenance tasks.dependencies
: Upgrading (sometimes downgrading) dependencies.build
: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup
: Minor cleanup style change. Will not show up in release changelog.documentation
: Documentation only changes. Will not show up in release changelog.feature request
: Introducing a new feature.BREAKING CHANGE
: Changes that break compatibility in some way with current major version.other
: Changes that don't fit in the above categories.cc @ndelangen