aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRubén Beltrán del Río <ben@nsovocal.com>2017-02-18 17:55:13 -0600
committerGitHub <noreply@github.com>2017-02-18 17:55:13 -0600
commit5e981bca19ace2a7704f267175b6aa368e63bda0 (patch)
treed38e6cbd1762837d3fae81b5029a9c0b48fa08b4 /lib
parentdc10b1de1a73effd6d0ab5744709913ef5cbe5b3 (diff)
Initial Setup (#1)
* Add git ignore * Add eslint config * Add dummy project files * Add jsdoc config * Add docker files * Add changelog, contributing and readme * Add travis files * Add Paw helper * Add travis test docker compose file * Name the ci service appropriately
Diffstat (limited to 'lib')
-rw-r--r--lib/dead_drop.js118
1 files changed, 118 insertions, 0 deletions
diff --git a/lib/dead_drop.js b/lib/dead_drop.js
new file mode 100644
index 0000000..1ea86e8
--- /dev/null
+++ b/lib/dead_drop.js
@@ -0,0 +1,118 @@
+'use strict';
+
+const Koa = require('koa');
+const KoaRoute = require('koa-route');
+
+const internals = {};
+
+/**
+ * The Dead Drop class is the main entry point for the application.
+ *
+ * @class DeadDrop
+ * @param {DeadDrop.tConfiguration} config the initialization options to
+ * extend the instance
+ */
+module.exports = internals.DeadDrop = class DeadDrop {
+
+ constructor(config) {
+
+ Object.assign(this, config);
+ }
+
+ /**
+ * Initializes the application and starts listening. Also prints a
+ * nice robotic banner with information.
+ *
+ * @function run
+ * @memberof DeadDrop
+ * @instance
+ */
+ run() {
+
+ this._initializeServer();
+ this._startServer();
+ this._printBanner();
+
+ return Promise.resolve();
+ }
+
+ // Initializes the Koa application and all the handlers.
+
+ _initializeServer() {
+
+ this._app = Koa();
+
+ this._app.use(KoaRoute.get('/menus/main', function * () {
+
+ this.body = 'I will return the main menu.';
+ }));
+
+ this._app.use(KoaRoute.post('/menus/main', function * () {
+
+ this.body = 'I will parse the main menu.';
+ }));
+
+ this._app.use(KoaRoute.get('/menus/recording', function * () {
+
+ this.body = 'I will return the select recording menu.';
+ }));
+
+ this._app.use(KoaRoute.post('/menus/recording', function * () {
+
+ this.body = 'I will parse the select recording menu.';
+ }));
+
+ this._app.use(KoaRoute.get('/recordings', function * () {
+
+ this.body = 'I will initiate recording process';
+ }));
+
+ this._app.use(KoaRoute.post('/recordings', function * () {
+
+ this.body = 'I will create a new recording';
+ }));
+
+ this._app.use(KoaRoute.get('/recordings/:id', function * (id) {
+
+ id = parseInt(id);
+
+ if (id === 0) {
+ this.body = 'I will return a random recording';
+ }
+ else {
+ this.body = 'I will return a specific recording';
+ }
+ }));
+
+ this._app.use(function * () {
+
+ this.body = 'hello, world';
+ });
+
+ }
+
+ // Starts listening
+
+ _startServer() {
+
+ this._app.listen(this.port);
+ }
+
+ // Prints the banner.
+
+ _printBanner() {
+
+ console.log(' >o<');
+ console.log(' /-----\\');
+ console.log(` |ú ù| - Happy to listen on: ${this.port}`);
+ console.log(' | U |');
+ console.log(' \\---/');
+ console.log(' +---------+');
+ console.log(' ~| () |~');
+ console.log(' ~| /\\ | ~');
+ console.log(' ~| \\/ | ~c');
+ console.log(' ^+---------+');
+ console.log(' (o==o==o) ');
+
+ }
+};