feat: export error handle & merge config

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2020-03-24 18:30:50 +08:00
parent 73b9c2f163
commit 49b96b3ac4
7 changed files with 44 additions and 41 deletions

View File

@@ -1,5 +1,6 @@
import { HttpRequestHandlerAdapter } from '../netty'
import { Keys, AttributeKeys } from './constants'
import { AttributeKeys } from './constants'
import { ServerOptions } from 'socket-io'
const DefaultHttpResponse = Java.type('io.netty.handler.codec.http.DefaultHttpResponse')
const DefaultFullHttpResponse = Java.type('io.netty.handler.codec.http.DefaultFullHttpResponse')
@@ -14,21 +15,13 @@ const RandomAccessFile = Java.type('java.io.RandomAccessFile')
const DefaultFileRegion = Java.type('io.netty.channel.DefaultFileRegion')
const ChannelFutureListener = Java.type('io.netty.channel.ChannelFutureListener')
export type HttpRequestConfig = {
root?: string;
ws?: string;
}
export class HttpRequestHandler extends HttpRequestHandlerAdapter {
private ws: string;
private root: string;
constructor(config: HttpRequestConfig = {
root: root + '/wwwroot',
ws: '/ws'
}) {
constructor(options: ServerOptions) {
super()
this.root = config.root;
this.ws = config.ws;
this.root = options.root;
this.ws = options.path;
}
channelRead0(ctx: any, request: any) {
if (request.getUri().startsWith(this.ws)) {