]>
git.r.bdr.sh - rbdr/dasein/blob - lib/dasein.js
3 const Koa
= require('koa');
4 const KoaJwt
= require('koa-jwt');
5 const KoaStatic
= require('koa-static');
6 const KoaRoute
= require('koa-route');
8 const AuthHandler
= require('./handlers/auth');
12 internals
.k401Location
= '/401.html';
13 internals
.kMainLocation
= '/';
15 module
.exports
= internals
.Dasein
= class Dasein
{
19 Object
.assign(this, config
);
24 this._initializeServer();
28 return Promise
.resolve();
35 this._app
.keys
= this.cookieKeys
;
37 this._app
.use(KoaStatic(this.staticDirectory
));
39 // Redirect all 401s to the 401 static page
41 this._app
.use(function * (next
) {
47 if (err
.status
=== 401) {
48 return this.redirect(internals
.k401Location
);
55 this._app
.use(KoaJwt({
56 secret: this.jwt
.secret
,
58 cookie: this.jwt
.cookieName
61 // Handlers for Twitter Auth Related Routes
63 const authHandler
= new AuthHandler({
64 hostname: this.hostname
,
68 this._app
.use(KoaRoute
.get('/login', authHandler
.login()));
69 this._app
.use(KoaRoute
.get('/login-callback', authHandler
.callback()));
70 this._app
.use(KoaRoute
.get('/logout', authHandler
.logout()));
74 this._app
.use(function * () {
76 if (this.state
.user
) {
77 this.body
= `<img src="${this.state.user.profile_image_url_https}"> Hello ${this.state.user.screen_name}`;
81 this.body
= 'Go to /login to login';
88 this._app
.listen(this.port
);
96 console
.log(' +-----+');
97 console
.log(` | o o | - Listening Gladly, Try me on port: ${this.port}`);
98 console
.log(' +-----+');
99 console
.log(' +---------+');
100 console
.log(' /| [][] |\\');
101 console
.log(' || | |');
102 console
.log(' || | \\c');
103 console
.log(' ^+---------+');
104 console
.log(' (.) ');