Skip to content

Commit 09a73e7

Browse files
committed
Refactor: update the example
1 parent 8e3c49c commit 09a73e7

File tree

6 files changed

+3097
-59
lines changed

6 files changed

+3097
-59
lines changed

examples/app/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const port = 3338;
1111
app.use(bodyParser.urlencoded({ extended: false }));
1212
app.use(bodyParser.json());
1313

14-
app.use('/', mapRoutes(routes));
14+
app.use('/', mapRoutes(routes, 'examples/app/controllers/'));
1515

16-
server.listen(port, function() {
16+
server.listen(port, () => {
1717
console.log('There we go ♕');
1818
console.log(`Gladly listening on http://127.0.0.1:${port}`);
1919
});

examples/app/config/routes.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const routes = {
2+
'GET /user:id': 'UserController.get',
3+
'POST /user': 'UserController.create',
4+
};
25

3-
'GET /user': 'UserController.get',
4-
'POST /user': 'UserController.create'
5-
6-
}
7-
8-
export default routes;
6+
export default routes;
Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,16 @@
1-
export default class UserController {
2-
3-
get (req,res) {
4-
5-
res.send('get user')
6-
7-
}
8-
9-
10-
create (req,res) {
11-
12-
res.send('created user: ' + req.body.name);
13-
14-
}
15-
16-
17-
destroy (req,res) {
18-
19-
res.send('get user')
20-
21-
}
22-
23-
24-
update (req,res) {
25-
26-
res.send('created user: ' + req.body.name);
27-
28-
}
29-
30-
}
1+
const UserController = () => {
2+
const get = (req, res) => {
3+
res.send(`user with id: ${req.params.id}`);
4+
};
5+
6+
const create = (req, res) => {
7+
res.send('created user');
8+
};
9+
10+
return {
11+
get,
12+
create,
13+
};
14+
};
15+
16+
export default UserController;
Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1-
var gulp = require("gulp");
2-
var sourcemaps = require("gulp-sourcemaps");
3-
var babel = require("gulp-babel");
4-
var concat = require("gulp-concat");
5-
var del = require("del");
6-
var path = require("path");
7-
var runSequence = require("run-sequence");
8-
var gulpLoadPlugins = require("gulp-load-plugins");
1+
import gulp from 'gulp';
2+
import del from 'del';
3+
import path from 'path';
4+
import runSequence from 'run-sequence';
5+
import gulpLoadPlugins from 'gulp-load-plugins';
96

107
const plugins = gulpLoadPlugins();
118

129
const paths = {
13-
js: ['app/**/*.js', '!dist/**', '!node_modules/**'],
14-
nonJs: ['./package.json', './.gitignore', './.env', './app/public/**/*'],
15-
tests: './server/tests/*.js'
10+
js: ['app/**/*.js', '!dist/**', '!node_modules/**'],
11+
nonJs: ['./package.json', './.gitignore', './.env', './app/public/**/*'],
12+
tests: './server/tests/*.js',
1613
};
1714

1815
gulp.task('clean', () =>
19-
del.sync(['dist/**', 'dist/.*'])
16+
del.sync(['dist/**', 'dist/.*']),
2017
);
2118

2219
gulp.task('copy', () =>
23-
gulp.src(paths.nonJs, {base: '.'})
20+
gulp.src(paths.nonJs, { base: '.' })
2421
.pipe(plugins.newer('dist'))
25-
.pipe(gulp.dest('dist'))
22+
.pipe(gulp.dest('dist')),
2623
);
2724

2825
gulp.task('babel', () =>
@@ -34,24 +31,24 @@ gulp.task('babel', () =>
3431
includeContent: false,
3532
sourceRoot(file) {
3633
return path.relative(file.path, __dirname);
37-
}
34+
},
3835
}))
39-
.pipe(gulp.dest('dist'))
36+
.pipe(gulp.dest('dist')),
4037
);
4138

4239
gulp.task('nodemon', ['copy', 'babel'], () =>
4340
plugins.nodemon({
4441
script: path.join('dist/app', 'app.js'),
4542
ext: 'js',
4643
ignore: ['node_modules/**/*.js', 'dist/**/*.js'],
47-
tasks: ['copy', 'babel']
48-
})
44+
tasks: ['copy', 'babel'],
45+
}),
4946
);
5047

5148
gulp.task('serve', ['clean'], () => runSequence('nodemon'));
5249

5350
gulp.task('default', ['clean'], () => {
5451
runSequence(
55-
['babel', 'copy']
52+
['babel', 'copy'],
5653
);
5754
});

examples/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
"author": "Lukas Aichbauer <rudolfson.junior@gmail.com> (https://github.com/rudolfsonjunior/)",
1010
"license": "MIT",
1111
"devDependencies": {
12+
"babel-polyfill": "^6.23.0",
1213
"babel-preset-env": "^1.1.11",
1314
"del": "^2.2.2",
1415
"gulp": "^3.9.1",
1516
"gulp-babel": "^6.1.2",
16-
"gulp-concat": "^2.6.1",
1717
"gulp-load-plugins": "^1.5.0",
1818
"gulp-newer": "^1.3.0",
1919
"gulp-nodemon": "^2.2.1",
@@ -23,6 +23,6 @@
2323
"dependencies": {
2424
"body-parser": "^1.17.1",
2525
"express": "^4.15.2",
26-
"express-routes-mapper": "0.0.x"
26+
"express-routes-mapper": "^0.1.1"
2727
}
2828
}

0 commit comments

Comments
 (0)