Skip to content

Commit

Permalink
GH-1 Add second example project
Browse files Browse the repository at this point in the history
including
- static files
- .development.json config overrides
- display of config files in web interface
  • Loading branch information
Thomas Rosenau committed Feb 10, 2016
1 parent fe6059e commit 66dc32b
Show file tree
Hide file tree
Showing 22 changed files with 267 additions and 1 deletion.
1 change: 1 addition & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/example/config/server.port.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"port": 8080,
"sslPort": 43
"sslPort": 4443
}
1 change: 1 addition & 0 deletions src/example2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.development.json
4 changes: 4 additions & 0 deletions src/example2/config/filesystem.path.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"public": "example2-public",
"mock": "example2-mocks"
}
4 changes: 4 additions & 0 deletions src/example2/config/server.port.development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"port": 8081,
"sslPort": 4444
}
4 changes: 4 additions & 0 deletions src/example2/config/server.port.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"port": 80,
"sslPort": 443
}
7 changes: 7 additions & 0 deletions src/example2/config/server.proxy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"backend": "https://api.github.com/users/SEITENBAU/repos",
"delayedServices": {
"/EXAMPLE": 42
},
"rejectUnauthorized": false
}
5 changes: 5 additions & 0 deletions src/example2/config/server.root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"root": "/example2",
"serviceBasePath": "rest/",
"defaultFile": "index.html"
}
11 changes: 11 additions & 0 deletions src/example2/config/services/DELETE.mock.development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"active": true,
"services": [
{
"active": true,
"path": "exampleEndpoint",
"file": "delete-result.example.json",
"delayBy": 5000
}
]
}
5 changes: 5 additions & 0 deletions src/example2/config/services/DELETE.mock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"active": true,
"services": [
]
}
10 changes: 10 additions & 0 deletions src/example2/config/services/GET.mock.development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"active": true,
"services": [
{
"active": true,
"path": "exampleEndpoint",
"file": "get-result.example.json"
}
]
}
5 changes: 5 additions & 0 deletions src/example2/config/services/GET.mock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"active": true,
"services": [
]
}
11 changes: 11 additions & 0 deletions src/example2/config/services/POST.mock.development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"active": true,
"services": [
{
"active": true,
"path": "exampleEndpoint",
"file": "post-result.example.json",
"delayBy": 100
}
]
}
5 changes: 5 additions & 0 deletions src/example2/config/services/POST.mock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"active": true,
"services": [
]
}
11 changes: 11 additions & 0 deletions src/example2/config/services/PUT.mock.development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"active": true,
"services": [
{
"active": true,
"path": "exampleEndpoint",
"file": "put-result.example.json",
"delayBy": 1000
}
]
}
6 changes: 6 additions & 0 deletions src/example2/config/services/PUT.mock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"active": true,
"services": [

]
}
4 changes: 4 additions & 0 deletions src/example2/example2-mocks/DELETE/delete-result.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"method": "DELETE",
"result": "ok"
}
5 changes: 5 additions & 0 deletions src/example2/example2-mocks/GET/get-result.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"method": "GET",
"result": "ok",
"foo": 42
}
4 changes: 4 additions & 0 deletions src/example2/example2-mocks/POST/post-result.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"method": "POST",
"result": "ok"
}
4 changes: 4 additions & 0 deletions src/example2/example2-mocks/PUT/put-result.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"method": "PUT",
"result": "ok"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
159 changes: 159 additions & 0 deletions src/example2/example2-public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<!doctype html>
<html lang=en>
<head>

<meta charset=utf-8>
<title>mix-n-mock!</title>
<style type="text/css">
html {
background: white;
}
body {
font: 16px / 1.2 Arial, sans-serif;
}
body:before {
display: block;
width: 200px;
height: 100px;
content: '';
float: right;
background: transparent top center no-repeat url('data:image/svg+xml;utf8,<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" viewBox="-11.6 -12.4 70 24.8"><g stroke-width="6" fill="none" stroke-linejoin="round" stroke-linecap="round" fill-opacity=".05"><circle r="8.2" stroke="%230d47a1" fill="%230d47a1"/><path d="M 17.2,9 l 1.5,-18 m 10,0 l -1.5,18" stroke="%23263238"/><path d="M 39,8 v -16 h 16 v 16 z" stroke="%23f57f17" fill="%23f57f17"/></g></svg>');
background-size: contain;
}

ul, li {
list-style: none;
padding: 0;
display: block;
margin: 0 0 1em;
}
ul {
padding-bottom: 20px;
clear: both;
}

body[data-loading] ul {
background: transparent left bottom no-repeat url("data:image/gif;base64,R0lGODlhEAAQAPQAAP///wAAAPDw8IqKiuDg4EZGRnp6egAAAFhYWCQkJKysrL6+vhQUFJycnAQEBDY2NmhoaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH+GkNyZWF0ZWQgd2l0aCBhamF4bG9hZC5pbmZvACH5BAAKAAAAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAEAAQAAAFdyAgAgIJIeWoAkRCCMdBkKtIHIngyMKsErPBYbADpkSCwhDmQCBethRB6Vj4kFCkQPG4IlWDgrNRIwnO4UKBXDufzQvDMaoSDBgFb886MiQadgNABAokfCwzBA8LC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5dOiBBIGxpbmsgdG8gdGhlIHNlcnZlciBjb3VsZCBub3QgYmUgZXN0YWJsaXNoZWQgaW4gPGI+L2hvbWUvYWpheGxvYWQvd3d3L2xpYnJhaXJpZXMvY2xhc3MubXlzcWwucGhwPC9iPiBvbiBsaW5lIDxiPjY4PC9iPjxiciAvPgo8YnIgLz4KPGI+V2FybmluZzwvYj46ICBteXNxbF9xdWVyeSgpIFs8YSBocmVmPSdmdW5jdGlvbi5teXNxbC1xdWVyeSc+ZnVuY3Rpb24ubXlzcWwtcXVlcnk8L2E+XTogQ2FuJ3QgY29ubmVjdCB0byBsb2NhbCBNeVNRTCBzZXJ2ZXIgdGhyb3VnaCBzb2NrZXQgJy92YXIvcnVuL215c3FsZC9teXNxbGQuc29jaycgKDIpIGluIDxiPi9ob21lL2FqYXhsb2FkL3d3dy9saWJyYWlyaWVzL2NsYXNzLm15c3FsLnBocDwvYj4gb24gbGluZSA8Yj42ODwvYj48YnIgLz4KPGJyIC8+CjxiPldhcm5pbmc8L2I+OiAgbXlzcWxfcXVlcnkoKSBbPGEgaHJlZj0nZnVuY3Rpb24ubXlzcWwtcXVlcnknPmZ1bmN0aW9uLm15c3FsLXF1ZXJ5PC9hPl06IEEgbGluayB0byB0aGUgc2VydmVyIGNvdWxkIG5vdCBiZSBlc3RhYmxpc2hlZCBpbiA8Yj4vaG9tZS9hamF4bG9hZC93d3cvbGlicmFpcmllcy9jbGFzcy5teXNxbC5waHA8L2I+IG9uIGxpbmUgPGI+Njg8L2I+PGJyIC8+Cg==");
}

button {
width: 15em;
height: 2em;
text-align: center;
}

a {
margin-top: 1em;
margin-bottom: 1em;
display: inline-block;
transition: opacity .3s ease-out;
}

div.config,
div.result {
font-family: monospace;
white-space: pre;
outline: 1px solid gray;
padding: .5em;
clear: left;
}
.hidden {
display: none;
}
</style>

</head>
<body>

<h1>Welcome to mix-n-mock</h1>
<h2>Advanced example</h2>
<a href="img/example.by.Marcelo.Quinan.from.unsplash.com-CC-zero.jpg" target="_blank">static file</a>
<ul>
<li>
<button type="submit" data-method="GET" data-action="rest/exampleEndpoint">
Submit GET-Request
</button>
<span>(no delay)</span>
</li>
<li>
<button type="submit" data-method="POST" data-action="rest/exampleEndpoint">
Submit POST-Request
</button>
<span>(100ms delay)</span>
</li>
<li>
<button type="submit" data-method="PUT" data-action="rest/exampleEndpoint">
Submit PUT-Request
</button>
<span>(1s delay)</span>
</li>
<li>
<button type="submit" data-method="DELETE" data-action="rest/exampleEndpoint">
Submit DELETE-Request
</button>
<span>(5s delay)</span>
</li>
</ul>
<div class="hidden">
<div class="result"></div>
<a class="show-config" href="#">Show method config</a>
<div class="config hidden"></div>
</div>
<script type="text/javascript">
var configs = {};
['POST', 'GET', 'PUT', 'DELETE'].forEach(function (method) {
var fileName = '/src/example2/config/services/' + method + '.mock.development.json';
var xhr = new XMLHttpRequest();
xhr.open('get', fileName, false);
xhr.send(null);
configs[method] = xhr.responseText + '\n\n' + fileName;
});
document.querySelector('.show-config').addEventListener('click', function (e) {
e.preventDefault();
var method = document.querySelector('.result').dataset.method;
var div = document.querySelector('.config');
div.style.display = 'block';
div.textContent = configs[method];
document.querySelector('.show-config').style.opacity = 0;
document.querySelector('.show-config').style.pointerEvents = 'none';
}, false);
</script>
<script type="text/javascript">
var loading = 0;
var div = document.querySelector('div.result');
Array.from(document.querySelectorAll('button')).forEach(function (button) {
button.addEventListener('click', function (e) {
e.preventDefault();
loading++;
document.body.dataset.loading = 1;
var url = button.dataset.action;
var xhr = new XMLHttpRequest();
var method = button.dataset.method;
xhr.open(method, url, true);
xhr.onreadystatechange = function () {
var innerHTML = 'Result of ' + method + ' to ' + button.dataset.action + ':\n\n';
if (xhr.readyState == 4) {
if (xhr.status == 200) {
innerHTML += xhr.responseText;
} else {
innerHTML += 'ERROR ' + xhr.status;
}
div.innerHTML = innerHTML;
div.parentNode.style.display = 'block';
div.dataset.method = method;
document.querySelector('.config').style.display = 'none';
document.querySelector('.show-config').style.opacity = 1;
document.querySelector('.show-config').style.pointerEvents = '';
loading--;
if (!loading) {
delete document.body.dataset.loading;
}
}
};
xhr.send('examplePayload: 42');
});
});
</script>

</body>
</html>

0 comments on commit 66dc32b

Please sign in to comment.