mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 12:19:51 +01:00
Added posts to the reoute separation example
This commit is contained in:
parent
14a22d9033
commit
5091c9e10f
|
|
@ -9,6 +9,7 @@ require.paths.unshift(__dirname + '/../../support');
|
|||
var express = require('express')
|
||||
, app = express.createServer()
|
||||
, site = require('./site')
|
||||
, post = require('./post')
|
||||
, user = require('./user');
|
||||
|
||||
// Config
|
||||
|
|
@ -32,5 +33,9 @@ app.get('/user/:id/view', user.view);
|
|||
app.get('/user/:id/edit', user.edit);
|
||||
app.put('/user/:id/edit', user.update);
|
||||
|
||||
// Posts
|
||||
|
||||
app.get('/posts', post.list);
|
||||
|
||||
app.listen(3000);
|
||||
console.log('Express app started on port 3000');
|
||||
17
examples/route-separation/post.js
Normal file
17
examples/route-separation/post.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
// Fake posts database
|
||||
|
||||
var posts = [
|
||||
{ title: 'Foo', body: 'some foo bar' }
|
||||
, { title: 'Foo bar', body: 'more foo bar' }
|
||||
, { title: 'Foo bar baz', body: 'more foo bar baz' }
|
||||
];
|
||||
|
||||
exports.list = function(req, res){
|
||||
res.render('post/list', {
|
||||
locals: {
|
||||
title: 'Posts'
|
||||
, posts: posts
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
@ -15,4 +15,10 @@ a.edit::before {
|
|||
}
|
||||
a.edit::after {
|
||||
content: ' ]';
|
||||
}
|
||||
dt {
|
||||
font-weight: bold;
|
||||
}
|
||||
dd {
|
||||
margin: 15px;
|
||||
}
|
||||
|
|
@ -1 +1,4 @@
|
|||
<p>Visit the <a href="/users">users</a> page</p>
|
||||
<ul>
|
||||
<li>Visit the <a href="/users">users</a> page</li>
|
||||
<li>Visit the <a href="/posts">posts</a> page</li>
|
||||
</ul>
|
||||
7
examples/route-separation/views/post/list.ejs
Normal file
7
examples/route-separation/views/post/list.ejs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<h1>Posts</h1>
|
||||
<dl id="posts">
|
||||
<% posts.forEach(function(post){ %>
|
||||
<dt><%= post.title %></dt>
|
||||
<dd><%= post.body %></dd>
|
||||
<% }) %>
|
||||
</dl>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<h1>Editing <%= user.name %></h1>
|
||||
<div id="user">
|
||||
<h1>Editing <%= user.name %></h1>
|
||||
<form method="post">
|
||||
<input type="hidden" value="put" name="_method" />
|
||||
<p>Name: <input type="text" value="<%= user.name %>" name="user[name]"/></p>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
<h1>Users</h1>
|
||||
<ul id="users">
|
||||
<% users.forEach(function(user, id){ %>
|
||||
<li>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<h1><%= user.name %></h1>
|
||||
<div id="user">
|
||||
<h1><%= user.name %></h1>
|
||||
<p>Email: <%= user.email %></p>
|
||||
</div>
|
||||
Loading…
Reference in New Issue
Block a user