Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use an HTTPS Agent and HTTPS scheme if RED.settings.https is set #1488

Open
wants to merge 2 commits into
base: widget-wysiwyg
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion nodes/config/ui_base.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { Agent } = require('https')
const path = require('path')

const axios = require('axios')
Expand Down Expand Up @@ -1130,7 +1131,26 @@ module.exports = function (RED) {
const host = RED.settings.uiHost
const port = RED.settings.uiPort
const httpAdminRoot = RED.settings.httpAdminRoot
const url = 'http://' + (`${host}:${port}/${httpAdminRoot}flows`).replace('//', '/')
let scheme = 'http://'
let httpsAgent
if (RED.settings.https) {
let https = RED.settings.https
try {
if (typeof https === 'function') {
// since https() could return a promise / be async, we need to await it
// if however the function is actually sync, JS will auto wrap it in a promise and await it
https = await https()
}
httpsAgent = new Agent({
rejectUnauthorized: false,
...(https || {})
})
scheme = 'https://'
} catch (error) {
return res.status(500).json({ error: 'Error processing https settings' })
}
}
const url = scheme + (`${host}:${port}/${httpAdminRoot}flows`).replace('//', '/')
console.log('url', url)
// get request body
const dashboardId = req.params.dashboardId
Expand Down Expand Up @@ -1234,6 +1254,7 @@ module.exports = function (RED) {
const getResponse = await axios.request({
method: 'GET',
headers: getHeaders,
httpsAgent,
url
})

Expand Down Expand Up @@ -1314,6 +1335,7 @@ module.exports = function (RED) {
const postResponse = await axios.request({
method: 'POST',
headers: postHeaders,
httpsAgent,
url,
data: {
flows,
Expand Down
Loading