Skip to content

Commit

Permalink
Refactor: update the example
Browse files Browse the repository at this point in the history
  • Loading branch information
aichbauer committed May 8, 2017
1 parent 8e3c49c commit 09a73e7
Show file tree
Hide file tree
Showing 6 changed files with 3,097 additions and 59 deletions.
4 changes: 2 additions & 2 deletions examples/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const port = 3338;
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.use('/', mapRoutes(routes));
app.use('/', mapRoutes(routes, 'examples/app/controllers/'));

server.listen(port, function() {
server.listen(port, () => {
console.log('There we go ♕');
console.log(`Gladly listening on http://127.0.0.1:${port}`);
});
10 changes: 4 additions & 6 deletions examples/app/config/routes.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const routes = {
'GET /user:id': 'UserController.get',
'POST /user': 'UserController.create',
};

'GET /user': 'UserController.get',
'POST /user': 'UserController.create'

}

export default routes;
export default routes;
46 changes: 16 additions & 30 deletions examples/app/controllers/UserController.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
export default class UserController {

get (req,res) {

res.send('get user')

}


create (req,res) {

res.send('created user: ' + req.body.name);

}


destroy (req,res) {

res.send('get user')

}


update (req,res) {

res.send('created user: ' + req.body.name);

}

}
const UserController = () => {
const get = (req, res) => {
res.send(`user with id: ${req.params.id}`);
};

const create = (req, res) => {
res.send('created user');
};

return {
get,
create,
};
};

export default UserController;
35 changes: 16 additions & 19 deletions examples/gulpfile.js → examples/gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
var gulp = require("gulp");
var sourcemaps = require("gulp-sourcemaps");
var babel = require("gulp-babel");
var concat = require("gulp-concat");
var del = require("del");
var path = require("path");
var runSequence = require("run-sequence");
var gulpLoadPlugins = require("gulp-load-plugins");
import gulp from 'gulp';
import del from 'del';
import path from 'path';
import runSequence from 'run-sequence';
import gulpLoadPlugins from 'gulp-load-plugins';

const plugins = gulpLoadPlugins();

const paths = {
js: ['app/**/*.js', '!dist/**', '!node_modules/**'],
nonJs: ['./package.json', './.gitignore', './.env', './app/public/**/*'],
tests: './server/tests/*.js'
js: ['app/**/*.js', '!dist/**', '!node_modules/**'],
nonJs: ['./package.json', './.gitignore', './.env', './app/public/**/*'],
tests: './server/tests/*.js',
};

gulp.task('clean', () =>
del.sync(['dist/**', 'dist/.*'])
del.sync(['dist/**', 'dist/.*']),
);

gulp.task('copy', () =>
gulp.src(paths.nonJs, {base: '.'})
gulp.src(paths.nonJs, { base: '.' })
.pipe(plugins.newer('dist'))
.pipe(gulp.dest('dist'))
.pipe(gulp.dest('dist')),
);

gulp.task('babel', () =>
Expand All @@ -34,24 +31,24 @@ gulp.task('babel', () =>
includeContent: false,
sourceRoot(file) {
return path.relative(file.path, __dirname);
}
},
}))
.pipe(gulp.dest('dist'))
.pipe(gulp.dest('dist')),
);

gulp.task('nodemon', ['copy', 'babel'], () =>
plugins.nodemon({
script: path.join('dist/app', 'app.js'),
ext: 'js',
ignore: ['node_modules/**/*.js', 'dist/**/*.js'],
tasks: ['copy', 'babel']
})
tasks: ['copy', 'babel'],
}),
);

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

gulp.task('default', ['clean'], () => {
runSequence(
['babel', 'copy']
['babel', 'copy'],
);
});
4 changes: 2 additions & 2 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"author": "Lukas Aichbauer <rudolfson.junior@gmail.com> (https://github.com/rudolfsonjunior/)",
"license": "MIT",
"devDependencies": {
"babel-polyfill": "^6.23.0",
"babel-preset-env": "^1.1.11",
"del": "^2.2.2",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-concat": "^2.6.1",
"gulp-load-plugins": "^1.5.0",
"gulp-newer": "^1.3.0",
"gulp-nodemon": "^2.2.1",
Expand All @@ -23,6 +23,6 @@
"dependencies": {
"body-parser": "^1.17.1",
"express": "^4.15.2",
"express-routes-mapper": "0.0.x"
"express-routes-mapper": "^0.1.1"
}
}

0 comments on commit 09a73e7

Please sign in to comment.