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

lab solved without PunkAPI #3000

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
24 changes: 21 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,37 @@ const PunkAPIWrapper = require('punkapi-javascript-wrapper');
const app = express();
const punkAPI = new PunkAPIWrapper();

//Configuration HBS view engine
app.set('view engine', 'hbs');
app.set('views', path.join(__dirname, 'views'));

//Set up static files (img, css)
app.use(express.static(path.join(__dirname, 'public')));

// Register the location for handlebars partials here:

// ...
hbs.registerPartials(__dirname + "/views/partials");

// Add the route handlers here:

app.get('/', (req, res) => {
res.render('index');
res.render("index");
});

app.get('/breweries', (req, res) => {
fetch('https://api.openbrewerydb.org/v1/breweries')
.then((response) => response.json())
.then((response) => {
res.render("breweries", {breweries: response})
});
});

app.get('/random-breweries', (req, res) => {
fetch('https://api.openbrewerydb.org/v1/breweries/random')
.then((response) => response.json())
.then((response) =>{
res.render('random-breweries', {breweries: response});
});

});

app.listen(3000, () => console.log('🏃‍ on port 3000'));
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"hbs": "^4.1.1",
"hbs": "^4.2.0",
"path": "^0.12.7",
"punkapi-javascript-wrapper": "^1.0.2"
}
}
29 changes: 29 additions & 0 deletions public/stylesheets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,32 @@ dark-blue: #0a2c42;
grey: #bfbfbf;
font-family: Arial, Helvetica, sans-serif;
*/

/* CSS for navbar */
.navbar {
background-color: #2081c3;
overflow: hidden;
}

.navbar a {
float: left;
display: block;
color: #f7f9f9;
text-align: center;
padding: 14px 20px;
text-decoration: none;
font-family: Arial, Helvetica, sans-serif;
}

.home {
display: flex;
flex-direction: column;
align-items: center;

}
.index-button {
background-color: #2081c3;
color: #f7f9f9;
padding: 0.5%;
}

6 changes: 6 additions & 0 deletions views/breweries.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Breweries</h1>
<ul>
{{#each breweries}}
<li>{{name}}</li>
{{/each}}
</ul>
12 changes: 10 additions & 2 deletions views/index.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<div>
<div class="home">

<img src="..\images\beer.png" alt="beer">

<button class="index-button">Check the Beers!</button>
<button class="index-button">Check a Random Beer!</button>

</div>



</div>
13 changes: 13 additions & 0 deletions views/layout.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="..\stylesheets\styles.css" />
<title>Document</title>
</head>
<body>
{{> navbar}}
{{{body}}}
<footer>Copyright &copy; 2024</footer>
</body>
</html>
5 changes: 5 additions & 0 deletions views/partials/navbar.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="navbar">
<a href="/">Home</a>
<a href="breweries">Breweries</a>
<a href="random-breweries">Random Breweries</a>
</div>
6 changes: 6 additions & 0 deletions views/random-breweries.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Random Breweries</h1>
<ul>
{{#each breweries}}
<li>{{name}}</li>
{{/each}}
</ul>