-
Notifications
You must be signed in to change notification settings - Fork 874
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 404 response is cached when static files not found (#308)
* fix: vercel cached 404 requests * fix: add static request fallback serverless
- Loading branch information
Showing
2 changed files
with
52 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @file static files not found fallback | ||
* According to the config in vercel.json, we cached the | ||
* static files with `max-age=X` header, but we may get 404 | ||
* response durning deploying, the default behavior for vercel | ||
* would add the cache header to this 404 response, which caused | ||
* the user can not get right resources anymore. so we should | ||
* fallback to here and clear the cache header for such 404 requests. | ||
* See also: https://github.com/conwnet/github1s/issues/299 | ||
* @author netcon | ||
*/ | ||
|
||
module.exports = async (req, res) => { | ||
res.status(404); | ||
res.setHeader('Cache-Control', 'no-store'); | ||
res.send('Not Found'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,49 @@ | ||
{ | ||
"routes": [ | ||
"rewrites": [ | ||
{ | ||
"src": "/api/sourcegraph", | ||
"dest": "https://sourcegraph.com/.api/graphql" | ||
"source": "/api/sourcegraph", | ||
"destination": "https://sourcegraph.com/.api/graphql" | ||
}, | ||
{ | ||
"src": "/static/(.*)", | ||
"dest": "/static/$1", | ||
"headers": { | ||
"Cache-Control": "max-age=604800" | ||
} | ||
"source": "/api/github-auth-callback", | ||
"destination": "/api/github-auth-callback" | ||
}, | ||
{ | ||
"src": "/favicon(-dark|-light)?.ico", | ||
"dest": "/favicon$1.ico" | ||
"source": "/static/(.*)", | ||
"destination": "/api/static-fallback" | ||
}, | ||
{ | ||
"src": "/manifest.json", | ||
"dest": "/manifest.json" | ||
"source": "/(.*)", | ||
"destination": "/index.html" | ||
} | ||
], | ||
"headers": [ | ||
{ | ||
"source": "/static/(.*)", | ||
"headers": [ | ||
{ | ||
"key": "Cache-Control", | ||
"value": "public, max-age=2592000, immutable" | ||
} | ||
] | ||
}, | ||
{ | ||
"src": "/api/github-auth-callback", | ||
"dest": "/api/github-auth-callback" | ||
"source": "/favicon(-dark|-light)?.ico", | ||
"headers": [ | ||
{ | ||
"key": "Cache-Control", | ||
"value": "public, max-age=3600" | ||
} | ||
] | ||
}, | ||
{ | ||
"src": ".*", | ||
"dest": "/index.html" | ||
"source": "/manifest.json", | ||
"headers": [ | ||
{ | ||
"key": "Cache-Control", | ||
"value": "public, max-age=3600" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} |