Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 8 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,17 @@ Two Mongoose Schema models are created (resources) to route and manipulate throu

##Dev dependencies
* Gulp
* Gulp-Eslint
* gulp-protractor
* Webpack-stream

### How to Use
Run mongo ```mongod --dbpath=./db
### How to test with protractor and selenium
Run a gulp command to bundle build, start server and run selenium and protractor:
```
Run ```node index
``` to start the client and backend servers.
Go to ```localhost:5000```

## Slugs and Rabbits
Enter Name, Type and Food in the test fields and click the update Slug or update Rabbit buttons.

New entry will display in url.
Example:
```http://localhost:5000/?name=Sven&type=black&food=leaf
gulp
```

### Database
See slugs by posting to localhost:4020/api/slugs

The databases is located at ```localhost:4020
or
```

```/api/rabbits
``` and ```/api/slugs
npm start
```

The angular app is located at ```localhost:5000
```
*Bella - the only concern I have for you running this, is the server I'm using for mongo in gulp is from my rest_api and I'm not sure it will exist for you? I followed Tyler's code on this. Please let me know if it's a problem and if you have any suggestions...
66 changes: 8 additions & 58 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -1,64 +1,14 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Slug and Rabbit dance off!</title>
<link rel="stylesheet" href="/css/style.css">
<meta charset="utf-8">
<title>Stuff</title>
<link rel="stylesheet" type="text/css" href="index.css">
</head>

<body data-ng-app="myApp">

<section data-ng-controller="SlugController" class="slug">

<ul id="sluglist">
<li dat-ng-repeat="Slug in sluglist">
{{slug.name}}, {{slug.type}}, eats: {{slug.food}}

<form data-ng-if="slug.editing" data-ng-submit="slug.updateSlug(Slug)">
<label for="name">Name</label>
<input type="text" name="name" data-ng-model="slug.name">

<label for="type">Type</label>
<input type="text" name="type" data-ng-model="slug.type">

<label for="food">Favorite food</label>
<input type="text" name="food" data-ng-model="slug.food">

<button type="submit">Update Slug</button>
<button data-ng-click="slug.editing = !slug.editing">Update!</button>
</form>

</li>
</ul>

</section>

<section data-ng-controller="RabbitController" class="rabbit">

<ul id="rabbitlist">
<li dat-ng-repeat="rabbit in rabbitlist">
{{rabbit.name}}, {{rabbit.type}}, eats: {{rabbit.food}}

<form data-ng-if="rabbit.editing" data-ng-submit="rabbitlist.updateRabbit(rabbit)">
<label for="name">Name</label>
<input type="text" name="name" data-ng-model="rabbit.name">

<label for="type">Type</label>
<input type="text" name="type" data-ng-model="rabbit.type">

<label for="food">Favorite food</label>
<input type="text" name="food" data-ng-model="rabbit.food">

<button type="submit">Update Rabbit</button>
<button data-ng-click="rabbit.editing = !rabbit.editing">Update!</button>
</form>

</li>
</ul>

</section>

<script type="text/javascript" src="/../build/bundle.js"></script>
<body data-ng-app="demoApp">
<h1 id="greeting">{{greeting}}</h1>
<input type="text/javascript" src="app/js/entry.js" data-ng-model="greeting">
<script src="./bundle.js"></script>
</body>

</html>
65 changes: 1 addition & 64 deletions app/js/entry.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,2 @@
const angular = require('angular');
const myApp = angular.module('myApp', []);
const baseUrl = 'http://localhost:5000';

var handleErrors = function(error) {
console.log(error);
this.errors = (this.errors || []).push(error);
};

myApp.controller('SlugController', ['$http', function($http) {
this.slug = [];
this.getAll = () => {
$http.get(baseUrl + '/api/slugs')
.then((res) => {
this.slug = res.data;
}, handleErrors.bind(this));
};

this.createSlug = () => {
$http.post(baseUrl + '/api/slugs', this.newSlug)
.then((res) => {
this.slug.push(res.data);
this.newSlug = null;
}, handleErrors.bind(this));
};

this.updateSlug = (slug) => {
$http.put(baseUrl + '/api/slugs' + slug._id, slug)
.then(() => {
slug.editing = false;
}, handleErrors.bind(this));
};
}]);

myApp.controller('RabbitController', ['$http', function($http) {
this.rabbit = [];
this.getAll = () => {
$http.get(baseUrl + '/api/rabbits')
.then((res) => {
this.rabbit = res.data;
}, handleErrors.bind(this));
};

this.createRabbit = () => {
$http.post(baseUrl + '/api/rabbits', this.newRabbit)
.then((res) => {
this.rabbit.push(res.data);
this.newRabbit = null;
}, handleErrors.bind(this));
};

this.updateRabbit = (rabbit) => {
$http.put(baseUrl + '/api/rabbits' + rabbit._id, rabbit)
.then(() => {
this.rabbit.splice(this.rabbit.indexOf(rabbit), 1);
}, handleErrors.bind(this));
};

this.deleteRabbit = (rabbit) => {
$http.delete(baseUrl + '/api/rabbits/' + rabbit._id)
.then(() => {
this.rabbit.splice(this.rabbit.indexOf(rabbit), 1);
}, handleErrors.bind(this));
};
}]);
const demoApp = angular.module('demoApp', []);
2 changes: 0 additions & 2 deletions client_server.js

This file was deleted.

72 changes: 38 additions & 34 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
var gulp = require('gulp');
var eslint = require('gulp-eslint');
var webpack = require('webpack-stream');
const gulp = require('gulp');
const webpack = require('webpack-stream');
const nodemon = require('gulp-nodemon');
const cp = require('child_process');
const exec = require('child_process').exec;
const protractor = require('gulp-protractor').protractor;
const mongoUri = 'mongodb://localhost/test_server';
var children = [];

var path = {
scripts: ['client_server.js', 'index.js', 'router/**/*.js',
'models/**/*.js', 'gulpfile.js'],
tests: [__dirname + '/test/server-test.js'],
client: ['app/js/entry.js']
};

gulp.task('lintServer', () => {
return gulp.src(path.scripts)
.pipe(eslint({
envs: [
'mocha',
'es6'
]
}))
.pipe(eslint.format());
});

gulp.task('lintClient', () => {
return gulp.src(path.client)
.pipe(eslint('./app/.eslintrc'))
.pipe(eslint.format());
});

gulp.task('entry', () => {
return gulp.src('app/js/entry.js')
gulp.task('webpack:dev', () => {
gulp.src('./app/js/entry.js')
.pipe(webpack({
output: {
filename: 'bundle.js'
Expand All @@ -36,11 +17,34 @@ gulp.task('entry', () => {
.pipe(gulp.dest('./build'));
});

gulp.task('html', () => {
return gulp.src('app/**/*.html')
gulp.task('static:dev', () => {
gulp.src('app/**/*.html')
.pipe(gulp.dest('./build'));
});

gulp.task('lint', ['lintServer', 'lintClient']);
gulp.task('build', ['entry', 'html']);
gulp.task('default', ['build', 'lint']);
gulp.task('css:dev', () => {
gulp.src('app/css/*.css')
.pipe(gulp.dest('./build'));
});

gulp.task('startservers:test', ['webpack:dev', 'static:dev', 'css:dev'], () => {
children.push(cp.fork('server.js'));
children.push(cp.spawn('webdriver-manager', ['start']));
children.push(cp.spawn('mongod', ['--dbpath=./db']));
children.push(cp.fork('../../week_3//rest_api/heidilaursen/server/server.js', [], {env: {MONGO_URI: mongoUri}}));
});

gulp.task('protractor', ['startservers:test'], () => {
gulp.src(['./test/*spec.js'])
.pipe(protractor({
configFile: 'test/config.js',
args: ['--baseUrl', 'http:127.0.0.1:5000']
}))
.on('end', () => {
children.forEach((child) => {
child.kill('SIGTERM');
});
});
});

gulp.task('default', ['protractor']);
2 changes: 0 additions & 2 deletions index.js

This file was deleted.

21 changes: 0 additions & 21 deletions lib/basic_http.js

This file was deleted.

4 changes: 0 additions & 4 deletions lib/errorHandler.js

This file was deleted.

19 changes: 0 additions & 19 deletions lib/jwt_auth.js

This file was deleted.

9 changes: 0 additions & 9 deletions models/rabbit.js

This file was deleted.

9 changes: 0 additions & 9 deletions models/slug.js

This file was deleted.

36 changes: 8 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,21 @@
{
"name": "heidilaursen",
"name": "week_6",
"version": "1.0.0",
"description": "Express api with REST and two Mongo databases. ",
"main": "node index.js",
"directories": {
"test": "test"
},
"description": "",
"main": "gulpfile.js",
"scripts": {
"test": " ./node_modules/mocha/bin/mocha test",
"start": "node index.js'"
},
"repository": {
"type": "git",
"url": "https://github.com/pnwlady/rest_api.git"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "gulp"
},
"keywords": [
"REST",
"Express",
"Mongodb"
],
"author": "Heidi Laursen",
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/pnwlady/rest_api/issues"
},
"homepage": "https://github.com/pnwlady/rest_api#readme",
"dependencies": {
"body-parser": "^1.15.0",
"express": "^4.13.4",
"mongodb": "^2.1.16",
"mongoose": "^4.4.13"
"express": "^4.13.4"
},
"devDependencies": {
"angular": "^1.5.5",
"gulp": "^3.9.1",
"gulp-eslint": "^2.0.0",
"gulp-protractor": "^2.3.0",
"gulp-protractor": "^2.4.0",
"webpack-stream": "^3.2.0"
}
}
Loading