]>
git.r.bdr.sh - rbdr/dead-drop/blob - lib/dead_drop.js
6f976459e18231d8ed5fbd0cb950b33b0024ca7d
3 const Koa
= require('koa');
4 const KoaBodyParser
= require('koa-bodyparser');
5 const KoaRoute
= require('koa-route');
7 const MainMenuController
= require('./controllers/main_menu');
8 const RecordingMenuController
= require('./controllers/recording_menu');
9 const RecordingsController
= require('./controllers/recordings');
14 * The Dead Drop class is the main entry point for the application.
17 * @param {DeadDrop.tConfiguration} config the initialization options to
20 module
.exports
= internals
.DeadDrop
= class DeadDrop
{
24 Object
.assign(this, config
);
28 * Initializes the application and starts listening. Also prints a
29 * nice robotic banner with information.
37 this._initializeServer();
41 return Promise
.resolve();
44 // Initializes the Koa application and all the handlers.
50 this._app
.use(KoaBodyParser());
52 this._initializeMainMenuRoutes();
53 this._initializeRecordingMenuRoutes();
54 this._initializeRecordingsRoutes();
56 this._app
.use(function * () {
58 this.body
= 'How did you get here? Shoo!';
67 this._app
.listen(this.port
);
70 // Initializes the main menu routes.
72 _initializeMainMenuRoutes() {
74 const mainMenuController
= new MainMenuController();
76 this._app
.use(KoaRoute
.get('/menus/main', mainMenuController
.serveMenu()));
77 this._app
.use(KoaRoute
.post('/menus/main', mainMenuController
.parseMenuSelection()));
80 // Initializes the recording menu routes.
82 _initializeRecordingMenuRoutes() {
84 const recordingMenuController
= new RecordingMenuController();
86 this._app
.use(KoaRoute
.get('/menus/recording', recordingMenuController
.serveMenu()));
87 this._app
.use(KoaRoute
.post('/menus/recording', recordingMenuController
.parseMenuSelection()));
90 // Initializes the recordings routes.
92 _initializeRecordingsRoutes() {
94 const recordingsController
= new RecordingsController({
98 this._app
.use(KoaRoute
.get('/recordings', recordingsController
.startRecording()));
99 this._app
.use(KoaRoute
.post('/recordings', recordingsController
.saveRecording()));
100 this._app
.use(KoaRoute
.get('/recordings/:id', recordingsController
.getRecording()));
103 // Prints the banner.
108 console
.log(' /-----\\');
109 console
.log(` |ú ù| - Happy to listen on: ${this.port}`);
110 console
.log(' | U |');
111 console
.log(' \\---/');
112 console
.log(' +---------+');
113 console
.log(' ~| () |~');
114 console
.log(' ~| /\\ | ~');
115 console
.log(' ~| \\/ | ~c');
116 console
.log(' ^+---------+');
117 console
.log(' (o==o==o) ');