Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
send form urlencoded data if not CORS
Browse files Browse the repository at this point in the history
closes #69
  • Loading branch information
andyshinn committed Jan 25, 2021
1 parent 634f9bb commit 9a853c7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/webhook.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { State } from "./runner";
import { State, InputState } from "./runner";

export interface Webhook {
url: string;
Expand All @@ -18,6 +18,10 @@ export function renderBody(state: State): string {
return JSON.stringify(state);
}

export function renderUrlEncoded(state: State): string {
return Object.entries(state.input).map((k, i) => `${k[0]}=${k[1]}`).join('&')
}

export function send(state: State, webhook: Webhook): Promise<Response> {
let options: RequestInit;

Expand All @@ -34,10 +38,10 @@ export function send(state: State, webhook: Webhook): Promise<Response> {
default:
options = {
method: "POST",
body: renderBody(state),
body: webhook.cors ? renderBody(state) : renderUrlEncoded(state),
mode: webhook.cors ? "cors" : "no-cors",
headers: {
"Content-Type": "application/json",
"Content-Type": webhook.cors ? "application/json" : "application/x-www-form-urlencoded",
},
};
}
Expand Down

0 comments on commit 9a853c7

Please sign in to comment.