Skip to content

Commit

Permalink
fix(twilio-run): fall back to /assets/index.html for root path
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dkundel committed Oct 14, 2021
1 parent 54bfeda commit 0d5aab9
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/twilio-run/src/runtime/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,15 @@ export async function createServer(
app.all(
'/*',
(req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
if (!routeMap.has(req.path)) {
res.status(404).send('Could not find request resource');
return;
let routeInfo = routeMap.get(req.path);

if (!routeInfo && req.path === '/') {
// In production we automatically fall back to the contents of /assets/index.html
debug('Falling back to /assets/index.html');
routeInfo = routeMap.get('/assets/index.html');
}

if (req.method === 'OPTIONS') {
if (req.method === 'OPTIONS' && routeInfo) {
res.set({
'access-control-allow-origin': '*',
'access-control-allow-headers':
Expand All @@ -268,8 +271,6 @@ export async function createServer(
return;
}

const routeInfo = routeMap.get(req.path);

if (routeInfo && routeInfo.type === 'function') {
const functionPath = routeInfo.filePath;
try {
Expand Down

0 comments on commit 0d5aab9

Please sign in to comment.