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

fumane_t #15

Open
wants to merge 3 commits into
base: master
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
7 changes: 6 additions & 1 deletion exercises/nodejs/02-interactive/index.js
Original file line number Diff line number Diff line change
@@ -29,10 +29,15 @@ prompt.get([{

console.log(`Welcome, ${result.name} !`);

tryAgain(function() {});
tryAgain(isFound);
});


function isFound (inutile, bool) {
if (!bool)
tryAgain(isFound);
}

function tryAgain(callback) {
prompt.get( [{
name: 'value',
44 changes: 28 additions & 16 deletions exercises/nodejs/03-promise/index.js
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ function askUser() {
}
], function (choices) {
console.log(choices);

return resolve(choices);
// TODO resolve the promise !!!
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
});
@@ -62,7 +62,19 @@ function fetchData(choices) {

// TODO now use the fetch API :
// https://developer.mozilla.org/fr/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful
return Promise.reject(new Error('fetchData not implemented !'));
return fetch(url).then(function onResponse(response) {
if(response.ok) {
spinner.stop();
return response.json();
}
else {
console.log('Network response was not ok.');
throw new Error('fetchData not implemented !');
}
}).catch(function(error) {
console.log('There has been a problem with your fetch operation: ' + error.message);
return Promise.reject(new Error('fetchData not implemented !'));
});
}

function displayResults(data) {
@@ -76,17 +88,17 @@ function getUrl () {
})
}

getUrl()
.then(function fetchData(url) {
return fetch(url)
.then(function onResponse(response) {
if(response.ok)
return response.json();
else
throw new Error('Network response was not ok.');
});
})
.then(function displayResults(data) {
console.log(data)
})
.catch(err => console.error(err));
// getUrl()
// .then(function fetchData(url) {
// return fetch(url)
// .then(function onResponse(response) {
// if(response.ok)
// return response.json();
// else
// throw new Error('Network response was not ok.');
// });
// })
// .then(function displayResults(data) {
// console.log(data)
// })
// .catch(err => console.error(err));
6 changes: 5 additions & 1 deletion exercises/nodejs/05-express_routing/index.js
Original file line number Diff line number Diff line change
@@ -30,7 +30,11 @@ app.use((req, res, next) => {
});

app.get('/', function(req, res) {
res.send('hello from app ! Try /meta /api');
res.sendfile('main.html');
});

app.get('/api', function(req, res) {

});

app.use('/api', api_router);
59 changes: 59 additions & 0 deletions exercises/nodejs/05-express_routing/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body style="background-color:#272b30;">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">API</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Documentation</a></li>
</ul>
</div>
</div>
</nav>
<div class="container" style="margin-top: 80px;">
<div id="list_request">
<ul>

</ul>
</div>
<div class="row pad_bot">
<div class="col-sm-1 col-lg-1 col-md-1">
</div>
<div class="col-sm-3 col-lg-3 col-md-3">
<h4 style="color:white;" class="center">What is this?</h4>
<p style="color:white;">The FuFu API is the world's first quanitified and programmatically-accessible data source for all the data from the lab pasteur</p>
<p style="color:white;">We've taken all the rich contextual stuff from the universe and formatted into something easier to consume with software. Then we went and stuck an API on the front so you can access it all!</p>
</div>
<div class="col-sm-4 col-lg-4 col-md-4">
<h4 style="color:white;" class="center">How can I use it?</h4>
<p style="color:white;">All the data is accessible through our HTTP web API. Consult our documentation if you'd like to get started.</p>
<p style="color:white;">Helper libraries for popular programming languages are also provided so you can consume swapi in your favourite programming language, in a style that suits you.</p>
</div>
<div class="col-sm-3 col-lg-3 col-md-3">
<h4 style="color:white;" class="center">How can I support this?</h4>
<p style="color:white;">With small donations we can keep swapi running for free, please consider throwing us some beer money to say thank you. With every $10 we can keep the site up for another month!</p>
</div>
<div class="col-sm-1 col-lg-1 col-md-1">
</div>
</div>
</div>
</body>
</html>
26 changes: 1 addition & 25 deletions src/server/web/index.js
Original file line number Diff line number Diff line change
@@ -30,31 +30,7 @@ app.use((req, res, next) => {

app.use(express.static(__dirname + '/../../client'));

app.get('/', (req, res) => res.send(`
<!DOCTYPE html>
<head>
<title>Node.js server</title>
<style type="text/css">
body {
margin: 40px;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
color: #333;
}
</style>
</head>

<h1>...</h1>
<li><a>${req.baseUrl}/chat</a>
<li><a>${req.baseUrl}/api</a>
<li><a>${req.baseUrl}/meta</a>

<script>
document.querySelector('h1').textContent = document.title;
Array.prototype.forEach.call(document.querySelectorAll('a'), function(el) {
el.href || (el.href = el.text);
});
</script>
`));
app.get('/', (req, res) => res.sendfile('main.html'););
app.use('/chat', chat_router);
app.use('/api', api_router);
app.use('/meta', meta_router);