remix icon indicating copy to clipboard operation
remix copied to clipboard

feat(remix-express): remove dependency on `express`

Open nicksrandall opened this issue 3 years ago • 3 comments

This PR removes express as a dependency from the "express" handler (using only vanilla http module). This allows the handler to be used by any "express like" router (like polka) or using http.createServer directly! This should improve remix's compatibility with many node based http server frameworks.

Example (using http.createServer & sirv)

import * as http from 'http';
import * as path from 'path';
import sirv from 'sirv';
import { createRequestHandler } from '@remix-run/express';

const BUILD_DIR = path.join(process.cwd(), "build");

const remixHandler = createRequestHandler({ build: require(BUILD_DIR) });

const server = http.createServer(sirv("public", {
	  maxAge: 3600,
	  setHeaders(res, pathname) {
		    if (pathname.startsWith("/build/")) {
		      res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
		    }
	  },
	  onNoMatch: remixHandler
}));

server.listen(process.env.PORT || 3000);

Closes: #

  • [ ] Docs
  • [ ] Tests

Testing Strategy:

All tests pass.

nicksrandall avatar May 18 '22 23:05 nicksrandall

Hi @nicksrandall,

Welcome, and thank you for contributing to Remix!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at [email protected].

Thanks!

- The Remix team

remix-cla-bot[bot] avatar May 18 '22 23:05 remix-cla-bot[bot]

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

remix-cla-bot[bot] avatar May 18 '22 23:05 remix-cla-bot[bot]

⚠️ No Changeset found

Latest commit: 312f245f0c4abc22588e94235a433d94c3545b1e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Nov 09 '22 21:11 changeset-bot[bot]

Looks like this PR got borked a bit with some unrelated changes related to .node files in https://github.com/remix-run/remix/pull/3234/commits/f724f0aaeaff9bbd30c3d62360409217deb3e20a. Mind fixing those up so we can take a look?

chaance avatar Jan 24 '23 00:01 chaance

This is the strangest thing but maybe I mixed up my PRs? This is code for a completely unrelated PR. Let me fix this.

nicksrandall avatar Jan 24 '23 04:01 nicksrandall

@nicksrandall no worries, I've done the same 😅 Usually happens because you try to fix two issues on the same branch and accidentally end up force-pushing to the wrong one.

chaance avatar Jan 24 '23 13:01 chaance

Closing in favor of #5237

nicksrandall avatar Jan 24 '23 18:01 nicksrandall