From edad5f1e487aa664280de3a36d74cf677bea7d23 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Wed, 19 Jan 2022 11:51:14 +0000 Subject: [PATCH] Add netlify deployment config --- .gitignore | 3 + netlify.toml | 18 +++++ netlify/functions/server/index.js | 28 +++++++ package-lock.json | 123 ++++++++++++++++++++++++++++++ package.json | 1 + remix.config.js | 3 +- 6 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 netlify.toml create mode 100644 netlify/functions/server/index.js diff --git a/.gitignore b/.gitignore index 18dfe68..28f236d 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ schema.graphql /cypress/videos /cypress/screenshots /runner-results + +# Local Netlify folder +.netlify diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 0000000..ec35702 --- /dev/null +++ b/netlify.toml @@ -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" diff --git a/netlify/functions/server/index.js b/netlify/functions/server/index.js new file mode 100644 index 0000000..ecf9c46 --- /dev/null +++ b/netlify/functions/server/index.js @@ -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 + ); + }; diff --git a/package-lock.json b/package-lock.json index 50e79f4..fd0bc8c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,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", @@ -225,6 +226,18 @@ "react-dom": "^16 || ^17 || ^18" } }, + "node_modules/@netlify/functions": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/@netlify/functions/-/functions-0.10.0.tgz", + "integrity": "sha512-NNFADTPnokuoMY1OUhaXlE/Jrzk5lHOl1uB4L/8pw1UJ/CaectZJACMExijbJnqaKIhOQG0WmbBQUh1lgnK/Qg==", + "peer": true, + "dependencies": { + "is-promise": "^4.0.0" + }, + "engines": { + "node": ">=8.3.0" + } + }, "node_modules/@node-redis/client": { "version": "1.0.1", "license": "MIT", @@ -374,6 +387,53 @@ "express": "^4.17.1" } }, + "node_modules/@remix-run/netlify": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@remix-run/netlify/-/netlify-1.1.1.tgz", + "integrity": "sha512-6eUw36ynCpisQbtf5UFMIVTuSX6HzK5bto/fq+Spp+pXDchM+3JEZKEiZfdWT3QCkc0QGCeC2VsLuBhyC5w35g==", + "dependencies": { + "@remix-run/node": "1.1.1", + "@remix-run/server-runtime": "1.1.1" + }, + "peerDependencies": { + "@netlify/functions": "^0.10.0" + } + }, + "node_modules/@remix-run/netlify/node_modules/@remix-run/node": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@remix-run/node/-/node-1.1.1.tgz", + "integrity": "sha512-8WhpjiDqHb+RpsN95vygYrxyui/dWKi9ECJju+/xBuP8pODRKXU9hrCoxVC2FjFRhXUdErkCEDK/AZSDPAlqVw==", + "dependencies": { + "@remix-run/server-runtime": "1.1.1", + "@types/busboy": "^0.3.1", + "@types/node-fetch": "^2.5.12", + "@web-std/file": "^3.0.0", + "abort-controller": "^3.0.0", + "blob-stream": "^0.1.3", + "busboy": "^0.3.1", + "cookie-signature": "^1.1.0", + "form-data": "^4.0.0", + "node-fetch": "^2.6.1", + "source-map": "^0.7.3" + } + }, + "node_modules/@remix-run/netlify/node_modules/@remix-run/server-runtime": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@remix-run/server-runtime/-/server-runtime-1.1.1.tgz", + "integrity": "sha512-uTTGSjCn2WTXUShruvTuErpbdbGoLu2dZ/zQ0ZHA0MMgP4VDA8xyuBeRcv/By3xqGcu2zSxcEGv7tRPgzU1AtA==", + "dependencies": { + "@types/cookie": "^0.4.0", + "cookie": "^0.4.1", + "jsesc": "^3.0.1", + "react-router-dom": "^6.2.1", + "set-cookie-parser": "^2.4.8", + "source-map": "^0.7.3" + }, + "peerDependencies": { + "react": ">=16.8", + "react-dom": ">=16.8" + } + }, "node_modules/@remix-run/node": { "version": "0.0.0-experimental-f218dd8b", "license": "MIT", @@ -4822,6 +4882,12 @@ "node": ">=0.10.0" } }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "peer": true + }, "node_modules/is-reference": { "version": "3.0.0", "dev": true, @@ -10553,6 +10619,15 @@ "version": "1.4.2", "requires": {} }, + "@netlify/functions": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/@netlify/functions/-/functions-0.10.0.tgz", + "integrity": "sha512-NNFADTPnokuoMY1OUhaXlE/Jrzk5lHOl1uB4L/8pw1UJ/CaectZJACMExijbJnqaKIhOQG0WmbBQUh1lgnK/Qg==", + "peer": true, + "requires": { + "is-promise": "^4.0.0" + } + }, "@node-redis/client": { "version": "1.0.1", "requires": { @@ -10651,6 +10726,48 @@ "@remix-run/server-runtime": "0.0.0-experimental-f218dd8b" } }, + "@remix-run/netlify": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@remix-run/netlify/-/netlify-1.1.1.tgz", + "integrity": "sha512-6eUw36ynCpisQbtf5UFMIVTuSX6HzK5bto/fq+Spp+pXDchM+3JEZKEiZfdWT3QCkc0QGCeC2VsLuBhyC5w35g==", + "requires": { + "@remix-run/node": "1.1.1", + "@remix-run/server-runtime": "1.1.1" + }, + "dependencies": { + "@remix-run/node": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@remix-run/node/-/node-1.1.1.tgz", + "integrity": "sha512-8WhpjiDqHb+RpsN95vygYrxyui/dWKi9ECJju+/xBuP8pODRKXU9hrCoxVC2FjFRhXUdErkCEDK/AZSDPAlqVw==", + "requires": { + "@remix-run/server-runtime": "1.1.1", + "@types/busboy": "^0.3.1", + "@types/node-fetch": "^2.5.12", + "@web-std/file": "^3.0.0", + "abort-controller": "^3.0.0", + "blob-stream": "^0.1.3", + "busboy": "^0.3.1", + "cookie-signature": "^1.1.0", + "form-data": "^4.0.0", + "node-fetch": "^2.6.1", + "source-map": "^0.7.3" + } + }, + "@remix-run/server-runtime": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@remix-run/server-runtime/-/server-runtime-1.1.1.tgz", + "integrity": "sha512-uTTGSjCn2WTXUShruvTuErpbdbGoLu2dZ/zQ0ZHA0MMgP4VDA8xyuBeRcv/By3xqGcu2zSxcEGv7tRPgzU1AtA==", + "requires": { + "@types/cookie": "^0.4.0", + "cookie": "^0.4.1", + "jsesc": "^3.0.1", + "react-router-dom": "^6.2.1", + "set-cookie-parser": "^2.4.8", + "source-map": "^0.7.3" + } + } + } + }, "@remix-run/node": { "version": "0.0.0-experimental-f218dd8b", "requires": { @@ -13617,6 +13734,12 @@ "version": "1.1.0", "dev": true }, + "is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "peer": true + }, "is-reference": { "version": "3.0.0", "dev": true, diff --git a/package.json b/package.json index c022ac7..d7224f2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/remix.config.js b/remix.config.js index 6b4d9f4..ad4922b 100644 --- a/remix.config.js +++ b/remix.config.js @@ -5,6 +5,7 @@ module.exports = { appDirectory: "app", assetsBuildDirectory: "public/build", publicPath: "/build/", - serverBuildDirectory: "./build", ignoredRouteFiles: [".*"], + serverBuildDirectory: "netlify/functions/server/build", + devServerPort: 8002, };