Skip to content

Commit f6755e1

Browse files
committed
updated gulpfile
1 parent 1d85e89 commit f6755e1

File tree

4 files changed

+183
-1
lines changed

4 files changed

+183
-1
lines changed

dist/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const express = require('express');
33
const logger = require('morgan');
44
const bodyParser = require('body-parser');
5+
const HeroRouter_1 = require('./routes/HeroRouter');
56
// Creates and configures an ExpressJS web server.
67
class App {
78
//Run configuration methods on the Express instance.
@@ -29,6 +30,7 @@ class App {
2930
});
3031
});
3132
this.express.use('/', router);
33+
this.express.use('/api/v1/heroes', HeroRouter_1.default);
3234
}
3335
}
3436
Object.defineProperty(exports, "__esModule", { value: true });

dist/data.json

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
[
2+
{
3+
"id": 1,
4+
"name": "Luke Cage",
5+
"aliases": ["Carl Lucas", "Power Man", "Mr. Bulletproof", "Hero for Hire"],
6+
"occupation": "bartender",
7+
"gender": "male",
8+
"height": {
9+
"ft": 6,
10+
"in": 3
11+
},
12+
"hair": "bald",
13+
"eyes": "brown",
14+
"powers": [
15+
"strength",
16+
"durability",
17+
"healing"
18+
]
19+
},
20+
{
21+
"id": 2,
22+
"name": "Spider-Man",
23+
"aliases": ["Dr. Peter Benjamin Parker", "Spidey", "Web-Sligner", "Spider-X-Man"],
24+
"occupation": "scientist",
25+
"gender": "male",
26+
"height": {
27+
"ft": 5,
28+
"in": 10
29+
},
30+
"hair": "brown",
31+
"eyes": "hazel",
32+
"powers": [
33+
"wall-crawling",
34+
"strength",
35+
"speed",
36+
"stamina",
37+
"durability",
38+
"agility",
39+
"healing",
40+
"reflexes",
41+
"Spider-Sense",
42+
"genius"
43+
]
44+
},
45+
{
46+
"id": 3,
47+
"name": "Captain America",
48+
"aliases": [
49+
"Winghead",
50+
"Shield-Slinger",
51+
"the Captain",
52+
"Cap",
53+
"Yeoman America",
54+
"Sentinel of Liberty",
55+
"The Living Legend"
56+
],
57+
"occupation": "special agent",
58+
"gender": "male",
59+
"height": {
60+
"ft": 6,
61+
"in": 2
62+
},
63+
"hair": "blonde",
64+
"eyes": "blue",
65+
"powers": [
66+
"strength",
67+
"speed",
68+
"durability",
69+
"agility",
70+
"reflexes",
71+
"stamina",
72+
"healing",
73+
"longevity"
74+
]
75+
},
76+
{
77+
"id": 4,
78+
"name": "Iron Man",
79+
"aliases": [
80+
"Tony Stark",
81+
"Golden Gladiator",
82+
"Spare Parts Man",
83+
"Space-Knight"
84+
],
85+
"occupation": "inventor",
86+
"gender": "male",
87+
"height": {
88+
"ft": 6,
89+
"in": 1
90+
},
91+
"hair": "black",
92+
"eyes": "blue",
93+
"powers": []
94+
},
95+
{
96+
"id": 5,
97+
"name": "Wolverine",
98+
"aliases": [
99+
"Logan",
100+
"Weapon X",
101+
"Death",
102+
"Agent Ten",
103+
"Fist of Legend"
104+
],
105+
"occupation": "special agent",
106+
"gender": "male",
107+
"height": {
108+
"ft": 5,
109+
"in": 3
110+
},
111+
"hair": "black",
112+
"eyes": "blue",
113+
"powers": [
114+
"healing",
115+
"acute senses",
116+
"strength",
117+
"speed",
118+
"durability",
119+
"agility",
120+
"stamina",
121+
"weather adaptation",
122+
"animal empathy",
123+
"bone claws"
124+
]
125+
}
126+
]

dist/routes/HeroRouter.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"use strict";
2+
const express_1 = require('express');
3+
const Heroes = require('../data');
4+
class HeroRouter {
5+
/**
6+
* Initialize the HeroRouter
7+
*/
8+
constructor() {
9+
this.router = express_1.Router();
10+
this.init();
11+
}
12+
/**
13+
* GET all Heroes.
14+
*/
15+
getAll(req, res, next) {
16+
res.send(Heroes);
17+
}
18+
/**
19+
* GET one hero by id
20+
*/
21+
getOne(req, res, next) {
22+
let query = parseInt(req.params.id);
23+
let hero = Heroes.find(hero => hero.id === query);
24+
if (hero) {
25+
res.status(200)
26+
.send({
27+
message: 'Success',
28+
status: res.status,
29+
hero
30+
});
31+
}
32+
else {
33+
res.status(404)
34+
.send({
35+
message: 'No hero found with the given id.',
36+
status: res.status
37+
});
38+
}
39+
}
40+
/**
41+
* Take each handler, and attach to one of the Express.Router's
42+
* endpoints.
43+
*/
44+
init() {
45+
this.router.get('/', this.getAll);
46+
this.router.get('/:id', this.getOne);
47+
}
48+
}
49+
exports.HeroRouter = HeroRouter;
50+
// Create the HeroRouter, and export its configured Express.Router
51+
const heroRoutes = new HeroRouter();
52+
heroRoutes.init();
53+
Object.defineProperty(exports, "__esModule", { value: true });
54+
exports.default = heroRoutes.router;

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ gulp.task('watch', ['scripts'], () => {
1717

1818
gulp.task('assets', function() {
1919
return gulp.src(JSON_FILES)
20-
.pipe(gulp.dest('dist'));
20+
.pipe(gulp.dest('dist'));
2121
});
2222

2323
gulp.task('default', ['watch', 'assets']);

0 commit comments

Comments
 (0)