Skip to content

Commit 54bfeda

Browse files
committed
fix(runtime-handler): fall back to assets/index.html for root path
In production the Functions environment will fall back to serving the contents of /assets/index.html if / is not registered as its own content. fix #371
1 parent 68232df commit 54bfeda

File tree

1 file changed

+7
-6
lines changed
  • packages/runtime-handler/src/dev-runtime

1 file changed

+7
-6
lines changed

packages/runtime-handler/src/dev-runtime/server.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,15 @@ export class LocalDevelopmentServer extends EventEmitter {
141141
app.all(
142142
'/*',
143143
(req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
144-
if (!this.routeMap.has(req.path)) {
145-
res.status(404).send('Could not find request resource');
146-
return;
144+
let routeInfo = this.routeMap.get(req.path);
145+
146+
if (!routeInfo && req.path === '/') {
147+
log('Falling back to /assets/index.html');
148+
// In production we automatically fall back to the contents of /assets/index.html
149+
routeInfo = this.routeMap.get('/assets/index.html');
147150
}
148151

149-
if (req.method === 'OPTIONS') {
152+
if (req.method === 'OPTIONS' && routeInfo) {
150153
res.set({
151154
'access-control-allow-origin': '*',
152155
'access-control-allow-headers':
@@ -163,8 +166,6 @@ export class LocalDevelopmentServer extends EventEmitter {
163166
return;
164167
}
165168

166-
const routeInfo = this.routeMap.get(req.path);
167-
168169
if (routeInfo && routeInfo.type === 'function') {
169170
const functionPath = routeInfo.filePath;
170171
try {

0 commit comments

Comments
 (0)