Skip to content

Commit 2ddef13

Browse files
committed
fix: handle redirects in dev
1 parent 445921c commit 2ddef13

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323
"@types/react": "^18.2.0",
2424
"@types/react-dom": "^18.2.0",
2525
"eslint": "^8.27.0",
26-
"rimraf": "^4.1.4",
2726
"typescript": "^5.2.2"
2827
},
2928
"engines": {
3029
"node": ">=18"
3130
}
32-
}
31+
}

remix.init/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ const edgeFilesToCopy = [
1919
];
2020

2121
// Netlify Functions template file changes
22-
const filesToCopy = [["README.md"], ["netlify-toml", "netlify.toml"]];
22+
const filesToCopy = [
23+
["README.md"],
24+
["netlify-toml", "netlify.toml"],
25+
["redirects", ".redirects"],
26+
];
2327

2428
async function copyTemplateFiles({ files, rootDirectory }) {
2529
for (const [file, target] of files) {
@@ -45,7 +49,6 @@ async function updatePackageJsonForEdge(directory) {
4549
// dev script is the same as the start script for Netlify Edge, "cross-env NODE_ENV=production netlify dev"
4650
scripts: {
4751
...scripts,
48-
predev: "rimraf ./.netlify/edge-functions/",
4952
dev: 'remix dev --manual -c "ntl dev --framework=#static"',
5053
},
5154
...restOfPackageJson,
@@ -70,10 +73,18 @@ async function updatePackageJsonForFunctions(directory) {
7073

7174
packageJson.update({
7275
...restOfPackageJson,
76+
scripts: {
77+
...scripts,
78+
build: "npm run redirects:enable && remix build",
79+
dev: "npm run redirects:disable && remix dev",
80+
"redirects:enable": "shx cp .redirects public/_redirects",
81+
"redirects:disable": "shx rm -f public/_redirects",
82+
},
7383
dependencies: {
7484
...dependencies,
7585
"@netlify/functions": "^2.0.0",
7686
"@netlify/remix-adapter": "^2.0.0",
87+
shx: "^0.3.4",
7788
},
7889
});
7990

remix.init/netlify-toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ publish = "public"
44

55
[dev]
66
command = "npm run dev"
7-
8-
[[redirects]]
9-
from = "/*"
10-
to = "/.netlify/functions/server"
11-
status = 200
7+
targetPort = 3000
128

139
# Set immutable caching for static files, because they have fingerprinted filenames
1410

remix.init/redirects

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This file is copied into the public folder during the build step and removed during dev.
2+
# If you need to add your own redirects, add them in netlify.toml or they will be overwritten.
3+
# Do not remove the line below. This is required to serve the site when deployed.
4+
/* /.netlify/functions/server 200

0 commit comments

Comments
 (0)