Skip to content

Commit

Permalink
Add netlify deployment config
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Jan 19, 2022
1 parent ec4982a commit edad5f1
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ schema.graphql
/cypress/videos
/cypress/screenshots
/runner-results

# Local Netlify folder
.netlify
18 changes: 18 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[build]
command = "remix build"
functions = "netlify/functions"
publish = "public"

[dev]
command = "remix watch"
port = 3000

[[redirects]]
from = "/*"
to = "/.netlify/functions/server"
status = 200

[[headers]]
for = "/build/*"
[headers.values]
"Cache-Control" = "public, max-age=31536000, s-maxage=31536000"
28 changes: 28 additions & 0 deletions netlify/functions/server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const path = require("path");
const {createRequestHandler} = require("@remix-run/netlify");

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

function purgeRequireCache() {
// purge require cache on requests for "server side HMR" this won't let
// you have in-memory objects between requests in development,
// netlify typically does this for you, but we've found it to be hit or
// miss and some times requires you to refresh the page after it auto reloads
// or even have to restart your server
for (const key in require.cache) {
if (key.startsWith(BUILD_DIR)) {
delete require.cache[key];
}
}
}

exports.handler =
process.env.NODE_ENV === "production"
? createRequestHandler({build: require("./build")})
: (event, context) => {
purgeRequireCache();
return createRequestHandler({build: require("./build")})(
event,
context
);
};
123 changes: 123 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"@headlessui/react": "^1.4.2",
"@reach/auto-id": "^0.16.0",
"@remix-run/netlify": "^1.1.1",
"@remix-run/node": "0.0.0-experimental-f218dd8b",
"@remix-run/react": "0.0.0-experimental-f218dd8b",
"@remix-run/serve": "0.0.0-experimental-f218dd8b",
Expand Down
3 changes: 2 additions & 1 deletion remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
appDirectory: "app",
assetsBuildDirectory: "public/build",
publicPath: "/build/",
serverBuildDirectory: "./build",
ignoredRouteFiles: [".*"],
serverBuildDirectory: "netlify/functions/server/build",
devServerPort: 8002,
};

0 comments on commit edad5f1

Please sign in to comment.