Skip to content

Commit 5ab0164

Browse files
author
Michael Henderson
committed
refactor(gen:endpoint): configurable route url
* Configurable route base, defaults to `/api/`. This only affects the client URL, the backend code will still be written to `server/api`. * Configurable pluralization of route, defaults to true. Closes angular-fullstack#338
1 parent 1bf2bd6 commit 5ab0164

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Diff for: app/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ var AngularFullstackGenerator = yeoman.generators.Base.extend({
181181
this.config.set('registerRoutesFile', 'server/routes.js');
182182
this.config.set('routesNeedle', '// Insert routes below');
183183

184+
this.config.set('routesBase', '/api/');
185+
this.config.set('pluralizeRoutes', true);
186+
184187
this.config.set('insertSockets', true);
185188
this.config.set('registerSocketsFile', 'server/config/socketio.js');
186189
this.config.set('socketsNeedle', '// Insert sockets below');
@@ -250,4 +253,4 @@ var AngularFullstackGenerator = yeoman.generators.Base.extend({
250253
}
251254
});
252255

253-
module.exports = AngularFullstackGenerator;
256+
module.exports = AngularFullstackGenerator;

Diff for: endpoint/index.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,22 @@ util.inherits(Generator, ScriptBase);
1414
Generator.prototype.askFor = function askFor() {
1515
var done = this.async();
1616
var name = this.name;
17+
18+
var base = this.config.get('routesBase') || '/api/';
19+
if(base.charAt(base.length-1) !== '/') {
20+
base = base + '/';
21+
}
22+
23+
// pluralization defaults to true for backwards compat
24+
if (this.config.get('pluralizeRoutes') !== false) {
25+
name = name + 's';
26+
}
27+
1728
var prompts = [
1829
{
1930
name: 'route',
2031
message: 'What will the url of your endpoint to be?',
21-
default: '/api/' + name + 's'
32+
default: base + name
2233
}
2334
];
2435

@@ -62,4 +73,4 @@ Generator.prototype.createFiles = function createFiles() {
6273
var dest = this.config.get('endpointDirectory') || 'server/api/' + this.name;
6374
this.sourceRoot(path.join(__dirname, './templates'));
6475
ngUtil.processDirectory(this, '.', dest);
65-
};
76+
};

0 commit comments

Comments
 (0)