Skip to content

Commit

Permalink
Add submission debugging, change production switch
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveALee committed Jun 16, 2022
1 parent d5fdd98 commit 4ae9968
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
10 changes: 7 additions & 3 deletions _functions/list-submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ function formEncodedToPOJO(formEncoded) {

exports.handler = async function (event, context) {
const response = (code, redir, body) =>
({ statusCode: redir ? 303 : code, // this is the correct redirect code, UA will GET
({ statusCode: redir ? 303 : code, // this is the correct redirect code, UA will GET the location header
//TDO check if Access-Control-Allow-Origin is actually needed or if can make more specific
headers: { ...{"content-type": "application/json", "Access-Control-Allow-Origin": "*"}, ...(redir ? { "Location": redir } : {}) },
body: body ? JSON.stringify(body, null, ' ') : ''
})
Expand All @@ -111,8 +112,11 @@ exports.handler = async function (event, context) {

console.info(`Processing form ${formData['repository']}/${formData['form_name']} ${formData['submission_ref']}`)

// uncomment following to stop GitHub action processing
// return response(200, mkURI(formData['success']), formData )
if (formData['DEBUG']) {
console.info("Debugging: returning form JSON and not calling GitHub")
const result = {formJSON: formData, form: event.body, headers: event.headers}
return response(200, false, result )
}

// Invoke GitHub Action
const res = await callGitHubWebhook(formData)
Expand Down
9 changes: 7 additions & 2 deletions _includes/list-submission-form.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@
success - url to redirect to when succeeded - requiured
failure - url to redirect to when failed - required
repository - repository containing the action - required
DEBUG_FUNCTION - pass DEBUG to submission function, causes function to return JSON rather than submitting to GitHub
DEBUG_USE_LOCAL_FUNCTION - use local/domain function rather than live one and set DEBUG
end - end of form
{% endcomment %}

{%- if include.type == 'start' -%}

{%- if include.action == nil -%}
{%- if include.DEBUG_USE_LOCAL_FUNCTION != nil -%}
{% assign action = "/.netlify/functions/list-submission" %}
{%- elsif include.action == nil -%}
{% assign action = "https://wai-website.netlify.app/.netlify/functions/list-submission" %}
{% else %}
{% assign action = include.action %}
Expand All @@ -32,13 +36,14 @@
{% assign method = include.method %}
{% endif -%}

{% if jekyll.environment == "production" %}
{% if site.env.WAI_LIVE_SITE %}
{%assign WAI_REFERRER_HACK = "/WAI"%}
{%else%}
{%assign WAI_REFERRER_HACK = ""%}
{%endif%}

{% capture args %}
{% if include.DEBUG_FUNCTION %}DEBUG:true, {% endif %}
{% if include.version %}form_version:{{include.version}}, {% endif %}
{% if include.ref %}submission_ref:{{include.ref}}, {% endif %}
success:{{WAI_REFERRER_HACK}}{{include.success}},
Expand Down
8 changes: 8 additions & 0 deletions _plugins/env-vars-plugin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Jekyll
class EnvVariables < Generator
def generate(site)
site.config['env'] = {}
ENV.each_pair { |k, v| site.config['env'][k] = v }
end
end
end

0 comments on commit 4ae9968

Please sign in to comment.