Skip to content

Commit

Permalink
feat(bin): Creates bin folder
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasdaiki committed Feb 15, 2018
1 parent b78cc4d commit b396dfd
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
81 changes: 81 additions & 0 deletions bin/bee-hook
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);
});
});
2 changes: 1 addition & 1 deletion package.json
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",
Expand Down

0 comments on commit b396dfd

Please sign in to comment.