- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
import 'babel-polyfill'
import os from 'os'
import path from 'path'
import fs from 'fs-extra'
import Koa from 'koa'
import Router from 'koa-router'
import koaBody from 'koa-body'
import WebSocket from 'ws'
import * as route from './routes'
const app = new Koa()
const router = new Router()
const wss = new WebSocket.Server({
perMessageDeflate: false,
port: 3003
});
const koabody = new koaBody({
multipart: true,
formidable: {uploadDir: os.tmpdir()}
})
wss.on('connection', ws => {
console.log('a websocket client connected')
})
app.use(router.routes());
router
.get('/', route.pages.listPages)
.post('/upload/:cat', koabody, async (ctx, next) => {
await route.upload[ctx.params.cat](ctx, next)
})
app.listen(3000);