Skip to content

Commit

Permalink
feat: warn if function app has non-http triggers (#201)
Browse files Browse the repository at this point in the history
* feat: warn if function app has non-http triggers

resolves #200

* chore: move node-fetch types to devDependencies
  • Loading branch information
anthonychu authored May 12, 2021
1 parent c31403e commit d53ec4c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
28 changes: 28 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"globrex": "^0.1.2",
"http-proxy": "^1.18.1",
"internal-ip": "^6.2.0",
"node-fetch": "^2.6.1",
"ora": "^5.4.0",
"rimraf": "^3.0.2",
"serve-static": "^1.14.1",
Expand All @@ -49,6 +50,7 @@
"@types/http-proxy": "^1.17.4",
"@types/jest": "^26.0.16",
"@types/mock-fs": "^4.13.0",
"@types/node-fetch": "^2.5.10",
"@types/serve-static": "^1.13.9",
"@types/shelljs": "^0.8.8",
"@types/wait-on": "^5.2.0",
Expand Down
18 changes: 18 additions & 0 deletions src/proxy/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import chalk from "chalk";
import fetch from "node-fetch";
import finalhandler from "finalhandler";
import fs from "fs";
import http from "http";
Expand Down Expand Up @@ -336,6 +337,23 @@ const requestHandler = (userConfig: SWAConfigFile | null) =>
const isApi = Boolean(SWA_CLI_API_LOCATION && SWA_CLI_API_URI);
if (isApi) {
await validateDevServerConfig(SWA_CLI_API_URI);
await validateFunctionTriggers();

async function validateFunctionTriggers() {
try {
const functionsResponse = await fetch(`${SWA_CLI_API_URI}/admin/functions`);
const functions = await functionsResponse.json();
const triggers = functions.map((f: any) => f.config.bindings.find((b: any) => /trigger$/i.test(b.type))).map((b: any) => b.type);

if (triggers.some((t: string) => !/^httptrigger$/i.test(t))) {
logger.error(
"\nFunction app contains non-HTTP triggered functions. Azure Static Web Apps managed functions only support HTTP functions. To use this function app with Static Web Apps, see 'Bring your own function app'.\n"
);
}
} catch {
logger.log("Unable to query functions trigger types.");
}
}
}

const server = createServer();
Expand Down

0 comments on commit d53ec4c

Please sign in to comment.