Skip to content
Open
Show file tree
Hide file tree
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
27 changes: 23 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1
orbs:
node: circleci/node@5.0.2

# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
say-hello:
# Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
# See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
docker:
- image: cimg/base:stable
# Add steps to the job
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
steps:
- checkout
- run:
name: "Say hello"
command: "echo Hello, World!"

# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
node-tests:
say-hello-workflow:
jobs:
- node/test
- say-hello
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\src\\server.js"
}
]
}
72 changes: 72 additions & 0 deletions client/client.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,79 @@
<link rel="stylesheet" type="text/css" href="/style.css">

<script>
const handleResponse = async (response) => {
// Based on the bodyParseExample
// Set up a reference to the content section
const content = document.querySelector('#content');

//Based on the status code, display something
switch(response.status) {
case 200: //success
content.innerHTML = `<b>Success</b>`;
break;
case 201: //created
content.innerHTML = '<b>Created</b>';
break;
case 204: //updated (no response back from server)
content.innerHTML = '<b>Updated (No Content)</b>';
return;
case 400: //bad request
content.innerHTML = `<b>Bad Request</b>`;
break;
default: //any other status code
content.innerHTML = `Error code not implemented by client.`;
break;
}

// Get the JSON from the response and display it (may be a message and/or the list of users)
let obj = await response.json();
content.innerHTML += `<p>${JSON.stringify(obj)}</p>`;
};

const requestUpdate = async (url, method) => {
const response = await fetch(url, {
method: method,
headers: {
'Accept': 'application/json'
}
});
}

const requestPost = async (url, method, data) => {
const response = await fetch(url, {
method: method,
headers: {
'Accept': 'application/json'
},
body: data
});
}

const init = () => {
// Set up the add user button
document.querySelector("#nameForm").addEventListener('submit', () => {
// Save the data from the user
const name = document.querySelector("#nameField").value;
const age = document.querySelector("#ageField").value;

// Create the body
const data = `name=${name}&age=${age}`;

// Send the request
requestPost("/addUser", "post", data);
});

// Set up the get user button
document.querySelector("#userForm").addEventListener('submit', () => {
const url = document.querySelector("#urlField").value;
const method = document.querySelector("#methodSelect").value;
console.log(url, method);
requestUpdate(url, method);
})
}

// Hoop up init so it happens when the window is loaded
window.onload = init;
</script>
</head>
<body>
Expand Down
Loading