aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Beltran <ben@nsovocal.com>2020-03-22 11:53:13 -0600
committerBen Beltran <ben@nsovocal.com>2020-03-22 11:53:13 -0600
commit3841606684ee3d233266ad490905076a3562842c (patch)
tree407adde62e5181cae2b0d3611bc6c18c00a20d67 /lib
parent00a6e8aa8dd06f8a2bd7ccccdccfcb6215cf4841 (diff)
Remove server
Diffstat (limited to 'lib')
-rw-r--r--lib/forum.js88
-rw-r--r--lib/middleware/handle_errors.js25
2 files changed, 0 insertions, 113 deletions
diff --git a/lib/forum.js b/lib/forum.js
deleted file mode 100644
index f09e8dd..0000000
--- a/lib/forum.js
+++ /dev/null
@@ -1,88 +0,0 @@
-import Koa from 'koa';
-
-import HandleErrors from './middleware/handle_errors.js';
-import KoaSend from 'koa-send';
-import KoaStatic from 'koa-static';
-import Path from 'path';
-
-/**
- * The Forum class is the main entry point for the backend application.
- *
- * @module Forum
- * @param {tForumBackendConfiguration} config the initialization options to
- * extend the instance
- */
-export default class Forum {
-
- constructor(config) {
-
- Object.assign(this, config);
- }
-
- /**
- * Initializes the application and starts listening. Also prints a
- * nice robotic banner with information.
- */
- run() {
-
- this._initializeServer();
- this._startServer();
- this._printBanner();
-
- return Promise.resolve();
- }
-
- // Initializes the Koa application and all the handlers.
-
- _initializeServer() {
-
- const self = this;
-
- this._app = new Koa();
- this._app.use(KoaStatic(this.staticDirectory));
-
- // Error handler
-
- this._app.use(HandleErrors);
-
- this._initializePostsRoutes();
-
- this._app.use(async function () {
-
- await KoaSend(this, Path.join(self.staticDirectory, 'index.html'));
- });
-
- }
-
- // Initialize routes for posts
-
- _initializePostsRoutes() {
-
- // Under construction
- }
-
-
- // Starts listening
-
- _startServer() {
-
- this._app.listen(this.port);
- }
-
- // Prints the banner.
-
- _printBanner() {
-
- console.log(' .');
- console.log(' /');
- console.log(' +-----+');
- console.log(` | o o | - Listening Gladly, Try me on port: ${this.port}`);
- console.log(' +-----+');
- console.log(' +---------+');
- console.log(' /| [][] |\\');
- console.log(' || | |');
- console.log(' || | \\c');
- console.log(' ^+---------+');
- console.log(' (.) ');
- }
-}
diff --git a/lib/middleware/handle_errors.js b/lib/middleware/handle_errors.js
deleted file mode 100644
index f969676..0000000
--- a/lib/middleware/handle_errors.js
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * Middleware to create responses for unhandled errors.
- */
-export default async function HandleErrors(next) {
-
- try {
- await next;
- }
- catch (err) {
- this.status = err.status || 500;
-
- const response = {
- error: err.message,
- status: this.status
- };
-
- if (response.status === 401) {
- response.error === 'Protected resource, use Authorization header to get access';
- }
-
- this.body = response;
-
- this.app.emit('error', err, this);
- }
-}