-
-
Save Industrial/78fd06515cb74338bca10402d1593911 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import path from 'path' | |
import zlib from 'zlib' | |
import fs from 'fs' | |
import Koa from 'koa' | |
import koaStatic from 'koa-static' | |
import koaBodyparser from 'koa-bodyparser' | |
import koaCompress from 'koa-compress' | |
import koaConvert from 'koa-convert' | |
import koaHandleError from 'koa-handle-error' | |
import koaMount from 'koa-mount' | |
import koaPassport from 'koa-passport' | |
import koaRouter from 'koa-router' | |
import koaSession from 'koa-generic-session' | |
const CWD = path.resolve(__dirname) | |
const HOST = process.env.IP || '0.0.0.0' | |
const PORT = /*process.env.PORT ||*/ 3000 | |
const ADDRESS = `http://${HOST}:${PORT}` | |
console.log() | |
console.log('CWD: ', CWD) | |
console.log('HOST: ', HOST) | |
console.log('PORT: ', PORT) | |
console.log('ADDRESS: ', ADDRESS) | |
console.log() | |
function errorHandler(error) { | |
console.error('KOA ERROR: ' + error.stack || error.message || error) | |
} | |
const router = koaRouter() | |
const app = new Koa() | |
app.keys = ['keyboardcat'] | |
const _use = app.use | |
app.use = x => _use.call(app, koaConvert(x)) | |
app | |
.use(koaHandleError(errorHandler)) | |
.use(koaBodyparser()) | |
.use(koaSession()) | |
.use(koaPassport.initialize()) | |
.use(koaPassport.session()) | |
.use(router.routes()) | |
.use(router.allowedMethods()) | |
.use(koaStatic(`${CWD}/../client`)) | |
.use(koaCompress({ | |
filter: (contentType) => /text/i.test(contentType), | |
threshold: 2048, | |
flush: zlib.Z_SYNC_FLUSH, | |
})) | |
console.log('Starting...') | |
app | |
.listen(PORT, HOST, () => { | |
console.log('Started.') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment