Skip to content

Commit 47fb82d

Browse files
committed
fix(server): disable cache in live mode & fix missing function
When live mode is enabled there's now an explicit HTTP Header set to disable caching. Additionally it will now throw an error message if no "handler" function was found fix #35
1 parent 80fbd27 commit 47fb82d

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"lodash.startcase": "^4.4.0",
6161
"log-symbols": "^2.2.0",
6262
"ngrok": "^3.0.1",
63+
"nocache": "^2.1.0",
6364
"ora": "^3.3.1",
6465
"pkg-install": "^1.0.0",
6566
"prompts": "^2.0.4",

src/runtime/server.ts

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import express, {
77
Request as ExpressRequest,
88
Response as ExpressResponse,
99
} from 'express';
10+
import nocache from 'nocache';
1011
import { StartCliConfig } from './cli/config';
1112
import { createLogger } from './internal/request-logger';
1213
import { setRoutes } from './internal/route-cache';
@@ -58,6 +59,10 @@ export async function createServer(
5859
app.use(createLogger(config));
5960
}
6061

62+
if (config.live) {
63+
app.use(nocache());
64+
}
65+
6166
if (config.legacyMode) {
6267
process.env.TWILIO_FUNCTIONS_LEGACY_MODE = config.legacyMode
6368
? 'true'
@@ -92,6 +97,13 @@ export async function createServer(
9297

9398
log('Load & route to function at "%s"', functionPath);
9499
const twilioFunction = loadTwilioFunction(functionPath, config);
100+
if (typeof twilioFunction !== 'function') {
101+
return res
102+
.status(404)
103+
.send(
104+
`Could not find a "handler" function in file ${functionPath}`
105+
);
106+
}
95107
functionToRoute(twilioFunction, config)(req, res, next);
96108
} catch (err) {
97109
log('Failed to retrieve function. %O', err);

0 commit comments

Comments
 (0)