Skip to content

Commit

Permalink
feat(@dpc-sdp/ripple-tide-webform): send basic auth for webform submi…
Browse files Browse the repository at this point in the history
…t if provided
  • Loading branch information
jeffdowdle committed Jan 14, 2025
1 parent d546ab2 commit 1b64b60
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createProxyMiddleware } from 'http-proxy-middleware'
import verifyCaptcha from '../../../utils/verifyCaptcha'

export const createWebformProxyHandler = async (event: H3Event) => {
const { public: config } = useRuntimeConfig()
const nuxtConfig = useRuntimeConfig()
const formId = event.context.params?.formId

if (!formId) {
Expand All @@ -30,10 +30,25 @@ export const createWebformProxyHandler = async (event: H3Event) => {
}

const proxyMiddleware = createProxyMiddleware({
target: config.tide.baseUrl,
target: nuxtConfig.public.tide.baseUrl,
pathRewrite: {
'^/api/tide/': '/api/v1/'
},
on: {
proxyReq(proxyReq) {
const basicAuthUser = nuxtConfig.tide.webformSubmit.username
const basicAuthPass = nuxtConfig.tide.webformSubmit.password

// if a username and password is provided, set the basic Authorization header
if (basicAuthUser && basicAuthPass) {
const basicAuthBase64 = Buffer.from(
`${basicAuthUser}:${basicAuthPass}`
).toString('base64')

proxyReq.setHeader('Authorization', `Basic ${basicAuthBase64}`)
}
}
},
logger: logger,
changeOrigin: true
})
Expand Down
4 changes: 4 additions & 0 deletions packages/ripple-tide-webform/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { defineNuxtConfig } from 'nuxt/config'
export default defineNuxtConfig({
runtimeConfig: {
tide: {
webformSubmit: {
username: '',
password: ''
},
captchaSecret: {
// Placeholder for captcha id: secret mapping
}
Expand Down

0 comments on commit 1b64b60

Please sign in to comment.