forked from green-fox-academy/jsa-bloodstone-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JSAB2-52 Troops backend (green-fox-academy#4)
* JSAB2-52, create troops backend * JSAB2-52, modify files with Router applied * JSAB2-52, modify package.json since main index.js was moved * JSAB2-52, fix eslint errors, rename the main file * JSAB2-52, modify package.json since main index.js was renamed as App.js
- Loading branch information
1 parent
8629334
commit dfe0d23
Showing
4 changed files
with
60 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const express = require('express'); | ||
|
||
const app = express(); | ||
const PORT = 4000; | ||
const { troops } = require('./routers'); | ||
|
||
app.use(express.json()); | ||
|
||
app.get('/', (req, res) => { | ||
res.status(200).send('Hello world'); | ||
}); | ||
|
||
app.use('/kingdom', troops); | ||
|
||
app.use((err, req, res, next) => { | ||
res.status(500).send('Something broke!'); | ||
next(err); | ||
}); | ||
|
||
app.listen(PORT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,5 @@ | ||
const express = require('express'); | ||
const troops = require('./troops'); | ||
|
||
const app = express(); | ||
const PORT = 4000; | ||
|
||
app.use(express.json()); | ||
|
||
app.get('/', (req, res) => { | ||
res.status(200).send('Hello world'); | ||
}); | ||
|
||
app.use((err, req, res, next) => { | ||
res.status(500).send('Something broke!'); | ||
next(err); | ||
}); | ||
|
||
app.listen(PORT); | ||
module.exports = { | ||
troops, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { Router } = require('express'); | ||
|
||
const router = Router(); | ||
|
||
const myTroops = { | ||
troops: [ | ||
{ | ||
id: 1, | ||
level: 1, | ||
hp: 1, | ||
attack: 1, | ||
defence: 1, | ||
started_at: 12345789, | ||
finished_at: 12399999, | ||
}, { | ||
id: 2, | ||
level: 1, | ||
hp: 1, | ||
attack: 1, | ||
defence: 1, | ||
started_at: 12345789, | ||
finished_at: 12399999, | ||
}, | ||
], | ||
}; | ||
|
||
function getTroops(req, res) { | ||
return res.status(200).send(myTroops); | ||
} | ||
|
||
router.get('/troops', getTroops); | ||
|
||
module.exports = router; |