]>
git.r.bdr.sh - rbdr/forum/blob - lib/forum.js
3 import HandleErrors
from './middleware/handle_errors.js';
4 import KoaSend
from 'koa-send';
5 import KoaStatic
from 'koa-static';
6 import Path
from 'path';
9 * The Forum class is the main entry point for the backend application.
12 * @param {tForumBackendConfiguration} config the initialization options to
15 export default class Forum
{
19 Object
.assign(this, config
);
23 * Initializes the application and starts listening. Also prints a
24 * nice robotic banner with information.
28 this._initializeServer();
32 return Promise
.resolve();
35 // Initializes the Koa application and all the handlers.
41 this._app
= new Koa();
42 this._app
.use(KoaStatic(this.staticDirectory
));
46 this._app
.use(HandleErrors
);
48 this._initializePostsRoutes();
50 this._app
.use(async
function () {
52 await
KoaSend(this, Path
.join(self
.staticDirectory
, 'index.html'));
57 // Initialize routes for posts
59 _initializePostsRoutes() {
69 this._app
.listen(this.port
);
78 console
.log(' +-----+');
79 console
.log(` | o o | - Listening Gladly, Try me on port: ${this.port}`);
80 console
.log(' +-----+');
81 console
.log(' +---------+');
82 console
.log(' /| [][] |\\');
83 console
.log(' || | |');
84 console
.log(' || | \\c');
85 console
.log(' ^+---------+');