]>
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.
11 * @param {tForumBackendConfiguration} config the initialization options to
14 export default class Forum
{
18 Object
.assign(this, config
);
22 * Initializes the application and starts listening. Also prints a
23 * nice robotic banner with information.
27 this._initializeServer();
31 return Promise
.resolve();
34 // Initializes the Koa application and all the handlers.
40 this._app
= new Koa();
41 this._app
.use(KoaStatic(this.staticDirectory
));
45 this._app
.use(HandleErrors
);
47 this._initializePostsRoutes();
49 this._app
.use(async
function () {
51 await
KoaSend(this, Path
.join(self
.staticDirectory
, 'index.html'));
56 // Initialize routes for posts
58 _initializePostsRoutes() {
68 this._app
.listen(this.port
);
77 console
.log(' +-----+');
78 console
.log(` | o o | - Listening Gladly, Try me on port: ${this.port}`);
79 console
.log(' +-----+');
80 console
.log(' +---------+');
81 console
.log(' /| [][] |\\');
82 console
.log(' || | |');
83 console
.log(' || | \\c');
84 console
.log(' ^+---------+');