Skip to content

Commit

Permalink
maybe works
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Reynolds committed May 2, 2024
1 parent 38e18de commit 662d9be
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
14 changes: 7 additions & 7 deletions labapp/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,16 @@ def manip3():
except (LabException, requests.RequestException, ValueError) as e:
return jsonify(status='fail', error=str(e))

@app.route('/_port1')
def port1():
"""Azure LB test"""
@app.route('/_port2', methods=['POST'])
def port2():
"""Friend test"""
try:
s = requests.Session()
s.headers.update({"User-Agent": "MCN-Lab-Runner/1.0"})
ns = eph_ns()
if not ns:
raise LabException("Ephemeral NS not set")
url = f"https://{ns}.{app.config['base_url']}/"
data = request.get_json()
print(data)
eph_ns = data['userInput']
url = f"https://{eph_ns}.{app.config['base_url']}/"
data = cloudapp_fetch(s, url, 7, 'info', {"method": "GET", "path": "/"})
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
Expand Down
16 changes: 12 additions & 4 deletions labapp/app/markdown/portability.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,21 @@ Host: eph-ns.mcn-lab.f5demos.com
}
```

<div class="left-aligned-button-container">
<button id="requestBtn2" class="btn btn-primary">Test Load Balancer</button>
<div class="container mt-4">
<div class="row">
<div class="col-md-6">
<div class="input-group mb-3">
<input type="text" id="inputText2" class="form-control"
placeholder="Enter your string here" aria-label="User input" value="wiggly-yellowtail">
<button id="requestBtn2" class="btn btn-primary" type="button">Test Load Balancer</button>
</div>
</div>
</div>
<div id="result2" class="mt-3"></div>
</div>
<div id="result2" class="mt-3"></div>
<script>
document.getElementById('requestBtn2').addEventListener('click', () => {
makeHttpRequest('requestBtn2', '/_manip2', 'result2');
makePostRequest('requestBtn2', '/_port2', 'result2', 'inputText2');
});
</script>

Expand Down
23 changes: 23 additions & 0 deletions labapp/app/static/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,26 @@ async function makeHttpRequest(buttonId, requestUrl, resultDivId) {
resultDiv.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
}

async function makePostRequest(buttonId, requestUrl, resultDivId, inputDataId) {
const button = document.getElementById(buttonId);
const resultDiv = document.getElementById(resultDivId);
const inputData = document.getElementById(inputDataId).value;
button.disabled = true;

try {
const response = await axios.post(requestUrl, { userInput: inputData });
if (response.data.status === 'success') {
const prettyJson = JSON.stringify(response.data.data, null, 4);
resultDiv.innerHTML = `<div class="alert alert-success"><b>Request Succeeded:</b><br><pre><code class="hljs">${prettyJson}</code></pre></div>`;
} else {
const errJson = JSON.stringify(response.data.error, null, 4);
resultDiv.innerHTML = `<div class="alert alert-danger"><b>Request Failed:</b><br><pre><code class="hljs">${errJson}</code></pre></div>`;
}
} catch (error) {
resultDiv.innerHTML = `<div class="alert alert-danger">Error: ${error.message}</div>`;
} finally {
button.disabled = false;
resultDiv.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
}

0 comments on commit 662d9be

Please sign in to comment.