diff --git a/app/index.js b/app/index.js index 82e3e0658..bd0bc8f96 100644 --- a/app/index.js +++ b/app/index.js @@ -368,6 +368,7 @@ Generator.prototype.appJs = function appJs() { }; Generator.prototype.createIndex = function createIndex() { + this.indexFile = this.indexFile.replace(/'/g, "'"); if (this.jade) { this.write(path.join(this.appPath, 'views', 'index.jade'), this.indexFile); } else { @@ -437,6 +438,8 @@ Generator.prototype.serverFiles = function () { this.template('../../templates/express/server.js', 'server.js'); this.template('../../templates/express/api.js', 'lib/controllers/api.js'); this.template('../../templates/express/index.js', 'lib/controllers/index.js'); + this.template('../../templates/express/config/express.js', 'lib/config/express.js'); + this.template('../../templates/express/config/middlewares/nocache.js', 'lib/config/middlewares/nocache.js'); }; Generator.prototype.mongoFiles = function () { diff --git a/templates/express/config/express.js b/templates/express/config/express.js new file mode 100644 index 000000000..3619bcb8a --- /dev/null +++ b/templates/express/config/express.js @@ -0,0 +1,34 @@ +'use strict'; + +var express = require('express'), + path = require('path'); + +module.exports = function(app) { + var rootPath = path.normalize(__dirname + '/../..'); + + app.configure('development', function(){ + app.use(require('connect-livereload')()); + app.use(express.static(path.join(rootPath, '.tmp'))); + app.use(express.static(path.join(rootPath, 'app'))); + app.use(express.errorHandler()); + app.set('views', rootPath + '/app/views'); + }); + + app.configure('production', function(){ + app.use(express.favicon(path.join(rootPath, 'public', 'favicon.ico'))); + app.use(express.static(path.join(rootPath, 'public'))); + app.set('views', rootPath + '/views'); + }); + + app.configure(function(){<% if (!jade) { %> + app.engine('html', require('ejs').renderFile); + app.set('view engine', 'html');<% } %><% if (jade) { %> + app.set('view engine', 'jade');<% } %> + app.use(express.logger('dev')); + app.use(express.bodyParser()); + app.use(express.methodOverride()); + + // Router needs to be last + app.use(app.router); + }); +}; \ No newline at end of file diff --git a/templates/express/config/middlewares/nocache.js b/templates/express/config/middlewares/nocache.js new file mode 100644 index 000000000..891ea9613 --- /dev/null +++ b/templates/express/config/middlewares/nocache.js @@ -0,0 +1,6 @@ +'use strict'; + +module.exports = function(req, res, next) { + res.header('Cache-Control', 'no-cache, private, no-store, must-revalidate'); + return next(); +}; \ No newline at end of file diff --git a/templates/express/server.js b/templates/express/server.js index c10da276d..0de900a8d 100644 --- a/templates/express/server.js +++ b/templates/express/server.js @@ -1,8 +1,8 @@ 'use strict'; // Module dependencies. -var express = require('express'), - path = require('path')<% if (mongo) { %>, +var express = require('express')<% if (mongo) { %>, + path = require('path'), fs = require('fs')<% } %>; var app = express(); @@ -21,45 +21,27 @@ require('./lib/db/dummydata'); <% } %> // Express Configuration -app.configure('development', function(){ - app.use(require('connect-livereload')()); - app.use(express.static(path.join(__dirname, '.tmp'))); - app.use(express.static(path.join(__dirname, 'app'))); - app.use(express.errorHandler()); - app.set('views', __dirname + '/app/views'); -}); - -app.configure('production', function(){ - app.use(express.favicon(path.join(__dirname, 'public', 'favicon.ico'))); - app.use(express.static(path.join(__dirname, 'public'))); - app.set('views', __dirname + '/views'); -}); - -app.configure(function(){<% if (!jade) { %> - app.engine('html', require('ejs').renderFile); - app.set('view engine', 'html');<% } %><% if (jade) { %> - app.set('view engine', 'jade');<% } %> - app.use(express.logger('dev')); - app.use(express.bodyParser()); - app.use(express.methodOverride()); - - // Router needs to be last - app.use(app.router); -}); +require('./lib/config/express')(app); // Controllers var api = require('./lib/controllers/api'), - controllers = require('./lib/controllers'); + index = require('./lib/controllers'); + +// Middlewares +var noCache = require('./lib/config/middlewares/nocache'); // Server Routes app.get('/api/awesomeThings', api.awesomeThings); // Angular Routes -app.get('/partials/*', controllers.partials); -app.get('/*', controllers.index); +app.get('/partials/*', noCache, index.partials); +app.get('/*', index.index); // Start server var port = process.env.PORT || 3000; app.listen(port, function () { console.log('Express server listening on port %d in %s mode', port, app.get('env')); -}); \ No newline at end of file +}); + +// Expose app +exports = module.exports = app; \ No newline at end of file diff --git a/templates/views/html/index.html b/templates/views/html/index.html index 9a5db8b29..58ba5815b 100644 --- a/templates/views/html/index.html +++ b/templates/views/html/index.html @@ -28,7 +28,7 @@ <% if (ngRoute) { %>
<% } else { - %>
<% + %>
<% } %> diff --git a/templates/views/jade/index.jade b/templates/views/jade/index.jade index a70c1c401..e34c8c11c 100644 --- a/templates/views/jade/index.jade +++ b/templates/views/jade/index.jade @@ -30,11 +30,10 @@ html.no-js div(class="container" ng-view)<% } else { %> - div(class="container" ng-include="'views/main'" ng-controller="MainCtrl")<% } %> + div(class="container" ng-include="'partials/main'" ng-controller="MainCtrl")<% } %> // Google Analytics: change UA-XXXXX-X to be your site's ID. script.