Skip to content

Commit

Permalink
Added support for clean urls with Ember, fixes #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
wbyoung committed Oct 14, 2014
1 parent 4b5ff5d commit 11b439a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
3 changes: 2 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ module.exports = yeoman.generators.Base.extend({
this.template('app/scripts/vendor.json');
if (this.components.ember) {
this.copy('app/templates/application.hbs');
this.copy('app/templates/index.hbs');
}
},

Expand All @@ -85,7 +86,7 @@ module.exports = yeoman.generators.Base.extend({

server: function() {
if (this.components.server) {
this.copy('server/application.js');
this.template('server/application.js');
this.copy('server/config/index.js');
this.copy('server/config/env/base.js');
this.copy('server/config/env/development.js');
Expand Down
13 changes: 12 additions & 1 deletion templates/app/scripts/application.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
'use strict';
<% if (components.ember) { %>
window.<%= _.classify(appname) %> = Ember.Application.create();
var <%= _.classify(appname) %> = Ember.Application.create();
<% if (components.server) { %>
<%= _.classify(appname) %>.Router.reopen({
location: 'history'
});

<%= _.classify(appname) %>.ApplicationAdapter = DS.RESTAdapter.extend({
namespace: 'api/v1'
});
<% } %>
// expose <%= _.classify(appname) %> globally
window.<%= _.classify(appname) %> = <%= _.classify(appname) %>;
<% } else { %>
$(function() {
// your code here
Expand Down
9 changes: 0 additions & 9 deletions templates/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
<div class="content">
<h1>Caribou with Ember</h1>
<p>
Caribou works great with Ember and will pre-compile your handlebars
templates for you. You can also use <a href="http://emblemjs.com">
Emblem.js</a> for any of your templates.
</p>
</div>

{{outlet}}
9 changes: 9 additions & 0 deletions templates/app/templates/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="content">
<h1>Caribou with Ember</h1>
<p>
Caribou works great with Ember and will pre-compile your handlebars
templates for you. You can also use <a href="http://emblemjs.com">
Emblem.js</a> for any of your templates.
</p>
</div>

21 changes: 18 additions & 3 deletions templates/server/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,38 @@ var favicon = require('serve-favicon');
var config = require('./config');

var app = express();
var resources = express();
resources.use(express.static(config.public));

if (config.env === 'development') {
resources.use(express.static(path.join(__dirname, '../app')));
var connectLivereload = require('connect-livereload');
app.use(connectLivereload({ port: process.env.LIVERELOAD_PORT || 35729 }));
app.use(morgan('dev'));
app.use(express.static(config.public));
app.use(express.static(path.join(__dirname, '../app')));
app.use(resources);
}
if (config.env === 'production') {
app.use(morgan('default'));
app.use(favicon(path.join(config.public, 'favicon.ico')));
app.use(express.static(config.public));
app.use(resources);
app.use(compression());
}
app.use(bodyParser.json());
app.use(methodOverride());
<% if (components.ember) { %>
// api routes
var api = express.Router();
api.get('/example', function(req, res) {
res.json({});
});

// single-page app routes
app.use('/api/v1', api);
app.get('/*', function(req, res, next) {
req.url = '/index.html';
next();
}, resources);
<% } %>
// expose app
module.exports = app;

Expand Down

0 comments on commit 11b439a

Please sign in to comment.