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

Finished hw #6

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Commit 3 - index.ejs view rendered at pokemon route
LehmanBrother committed Oct 10, 2018
commit a6c59277c57ab9778b33ae53399bc7d87ccb5f5e
4 changes: 3 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
@@ -14,5 +14,7 @@ app.use(bodyParser.json());

//index route
app.get('/pokemon', (req,res) => {
res.send(Pokemon);
res.render('index.ejs', {
pokemon: Pokemon
});
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd recommend organizing this file a little more carefully. have a separate section for controllers and put all your controller stuff there (even though they are implemented the same way middleware is). example:

const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const methodOverride = require('method-override');

//middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(methodOverride('_method'));
app.use(express.static('public'));

// controllers
app.use('/pokemon', pokemonController);
const pokemonController = require('./controllers/pokemon');

app.get('/',(req, res) => {
	res.send('This is the server responding to a get request')
})

app.listen(3000, () => {
	console.log('server is listening on port 3000');
})

20 changes: 20 additions & 0 deletions views/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>Pokemon Index</title>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<style>
li {font-family: roboto;}
</style>
</head>
<body>
<h1>Pokemon Index</h1>
<ul class="pokemon">
<% for(let i = 0; i < pokemon.length; i++) {%>
<li>
<a href='/pokemon/<%=i%>'><%= pokemon[i].name %></a>
</li>
<% }%>
</ul>
</body>
</html>