-
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.
- Loading branch information
1 parent
b78cc4d
commit b396dfd
Showing
2 changed files
with
82 additions
and
1 deletion.
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,81 @@ | ||
#!/usr/bin/env node | ||
|
||
const express = require('express'); | ||
const bodyParser = require('body-parser'); | ||
const argv = require('optimist') | ||
.boolean('cors') | ||
.argv; | ||
|
||
const BinRepository = require('../src/BinRepository'); | ||
|
||
const app = express(); | ||
const PORT = argv.p || process.env.PORT || 5000; | ||
|
||
const binRepository = new BinRepository(); | ||
|
||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(bodyParser.json()); | ||
|
||
app.listen(PORT, () => { | ||
console.log(`Listening on port ${PORT}`); | ||
}); | ||
|
||
app.post('/bin', (req, res) => { | ||
return binRepository.generateHash() | ||
.then((hash) => { | ||
res.send(hash); | ||
res.status(200); | ||
}) | ||
.catch(() => { | ||
res.send('Error on create bin. Please try again'); | ||
res.status(400); | ||
}) | ||
}); | ||
|
||
app.post('/bin/:hash', (req, res) => { | ||
return binRepository.create(req.params.hash, req) | ||
.then(() => { | ||
res.status(200); | ||
res.end(); | ||
}) | ||
.catch(error => { | ||
res.status(404); | ||
res.send(error); | ||
}); | ||
}); | ||
|
||
app.get('/bin/:hash', (req, res) => { | ||
return binRepository.getByHash(req.params.hash) | ||
.then((result) => { | ||
res.status(200); | ||
res.send(result); | ||
}) | ||
.catch(error => { | ||
res.status(404); | ||
res.send(error); | ||
}); | ||
}); | ||
|
||
app.get('/bin/', (req, res) => { | ||
return binRepository.getAll() | ||
.then((result) => { | ||
res.status(200); | ||
res.send(result); | ||
}) | ||
.catch(error => { | ||
res.status(404); | ||
res.send(error); | ||
}); | ||
}); | ||
|
||
app.delete('/bin/:hash', (req, res) => { | ||
return binRepository.deleteHash(req.params.hash) | ||
.then(() => { | ||
res.status(200); | ||
res.end(); | ||
}) | ||
.catch(error => { | ||
res.status(404); | ||
res.send(error); | ||
}); | ||
}); |
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,5 +1,5 @@ | ||
{ | ||
"name": "hook-mock", | ||
"name": "@beetech/hook-mock", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
|