Skip to content

Commit 0d5aab9

Browse files
committed
fix(twilio-run): 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 54bfeda commit 0d5aab9

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

packages/twilio-run/src/runtime/server.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,15 @@ export async function createServer(
246246
app.all(
247247
'/*',
248248
(req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
249-
if (!routeMap.has(req.path)) {
250-
res.status(404).send('Could not find request resource');
251-
return;
249+
let routeInfo = routeMap.get(req.path);
250+
251+
if (!routeInfo && req.path === '/') {
252+
// In production we automatically fall back to the contents of /assets/index.html
253+
debug('Falling back to /assets/index.html');
254+
routeInfo = routeMap.get('/assets/index.html');
252255
}
253256

254-
if (req.method === 'OPTIONS') {
257+
if (req.method === 'OPTIONS' && routeInfo) {
255258
res.set({
256259
'access-control-allow-origin': '*',
257260
'access-control-allow-headers':
@@ -268,8 +271,6 @@ export async function createServer(
268271
return;
269272
}
270273

271-
const routeInfo = routeMap.get(req.path);
272-
273274
if (routeInfo && routeInfo.type === 'function') {
274275
const functionPath = routeInfo.filePath;
275276
try {

0 commit comments

Comments
 (0)