Skip to content

Commit 3507748

Browse files
committed
added example api call to controllers
added api route to server
1 parent a7444ff commit 3507748

File tree

7 files changed

+37
-31
lines changed

7 files changed

+37
-31
lines changed

Diff for: app/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,5 @@ Generator.prototype.packageFiles = function () {
261261

262262
Generator.prototype.serverFiles = function () {
263263
this.template('../../templates/express/server.js', 'server.js');
264+
this.template('../../templates/express/server/routes/index.js', 'server/routes/index.js');
264265
};

Diff for: templates/coffeescript-min/controller.coffee

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
'use strict'
22

33
angular.module('<%= _.camelize(appname) %>App')
4-
.controller '<%= _.classify(name) %>Ctrl', ['$scope', ($scope) ->
5-
$scope.awesomeThings = [
6-
'HTML5 Boilerplate'
7-
'AngularJS'
8-
'Karma'
9-
]
4+
.controller '<%= _.classify(name) %>Ctrl', ['$scope', '$http', ($scope, $http) ->
5+
$http.get('/api/awesomeThings').success (awesomeThings) ->
6+
$scope.awesomeThings = awesomeThings
107
]

Diff for: templates/coffeescript/controller.coffee

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
'use strict'
22

33
angular.module('<%= _.camelize(appname) %>App')
4-
.controller '<%= _.classify(name) %>Ctrl', ($scope) ->
5-
$scope.awesomeThings = [
6-
'HTML5 Boilerplate'
7-
'AngularJS'
8-
'Karma'
9-
]
4+
.controller '<%= _.classify(name) %>Ctrl', ($scope, $http) ->
5+
$http.get('/api/awesomeThings').success (awesomeThings) ->
6+
$scope.awesomeThings = awesomeThings

Diff for: templates/express/server.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
var express = require('express')
66
, http = require('http')
7-
, path = require('path');
7+
, path = require('path')
8+
, routes = require('./server/routes');
89

910
var app = express();
1011

@@ -18,14 +19,18 @@ app.use(express.methodOverride());
1819
app.use(app.router);
1920

2021
// development only
21-
if ('production' == app.get('env')) {
22-
app.use(express.static(path.join(__dirname, 'dist')));
23-
} else {
22+
if ('development' == app.get('env')) {
2423
app.use(express.static(path.join(__dirname, '.tmp')));
2524
app.use(express.static(path.join(__dirname, 'app')));
26-
app.use(express.errorHandler());
25+
app.use(express.errorHandler());
26+
}
27+
// production only
28+
else {
29+
app.use(express.static(path.join(__dirname, 'dist')));
2730
}
2831

32+
app.get('/api/awesomeThings', routes.awesomeThings);
33+
2934
http.createServer(app).listen(app.get('port'), function () {
3035
console.log("Express server listening on port %d in %s mode", app.get('port'), app.get('env'));
3136
});

Diff for: templates/express/server/routes/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
exports.awesomeThings = function(req, res) {
4+
res.json([
5+
'HTML5 Boilerplate',
6+
'AngularJS',
7+
'Karma',
8+
'Express'
9+
]);
10+
};

Diff for: templates/javascript-min/controller.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
'use strict';
22

33
angular.module('<%= _.camelize(appname) %>App')
4-
.controller('<%= _.classify(name) %>Ctrl', ['$scope', function ($scope) {
5-
$scope.awesomeThings = [
6-
'HTML5 Boilerplate',
7-
'AngularJS',
8-
'Karma'
9-
];
10-
}]);
4+
.controller('<%= _.classify(name) %>Ctrl', ['$scope', '$http', function ($scope, $http) {
5+
$http.get('/api/awesomeThings').success(function(awesomeThings) {
6+
$scope.awesomeThings = awesomeThings;
7+
});
8+
}]);

Diff for: templates/javascript/controller.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
'use strict';
22

33
angular.module('<%= _.camelize(appname) %>App')
4-
.controller('<%= _.classify(name) %>Ctrl', function ($scope) {
5-
$scope.awesomeThings = [
6-
'HTML5 Boilerplate',
7-
'AngularJS',
8-
'Karma'
9-
];
10-
});
4+
.controller('<%= _.classify(name) %>Ctrl', ['$scope', '$http', function ($scope, $http) {
5+
$http.get('/api/awesomeThings').success(function(awesomeThings) {
6+
$scope.awesomeThings = awesomeThings;
7+
});
8+
}]);

0 commit comments

Comments
 (0)