-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
97 additions
and
28 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
packages/client-rpc/src/jsonrpc/index.js → packages/client-rpc/src/create/index.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
// ISC, Copyright 2017 Jaco Greeff | ||
// @flow | ||
|
||
const createKoa = require('./koa'); | ||
const createError = require('./error'); | ||
const createResponse = require('./response'); | ||
|
||
module.exports = { | ||
createKoa, | ||
createError, | ||
createResponse | ||
}; |
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// ISC, Copyright 2017 Jaco Greeff | ||
// @flow | ||
|
||
import type { RpcType } from '../types'; | ||
|
||
type CreateKoaOptionType = { | ||
handlers: { | ||
http: Function, | ||
ws: Function | ||
}, | ||
path: string, | ||
types: Array<RpcType> | ||
}; | ||
|
||
const Koa = require('koa'); | ||
const koaRoute = require('koa-route'); | ||
const koaWebsocket = require('koa-websocket'); | ||
|
||
module.exports = function createKoa ({ handlers, path, types }: CreateKoaOptionType): Koa { | ||
let app = new Koa(); | ||
|
||
if (types.includes('http')) { | ||
app.use( | ||
koaRoute.post(path, handlers.http) | ||
); | ||
} | ||
|
||
if (types.includes('ws')) { | ||
app = koaWebsocket(app); | ||
|
||
(app: any).ws.use( | ||
koaRoute.all(path, handlers.ws) | ||
); | ||
} | ||
|
||
return app; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// ISC, Copyright 2017 Jaco Greeff | ||
|
||
const createKoa = require('./koa'); | ||
|
||
describe('createKoa', () => { | ||
it('creates an HTTP interface', () => { | ||
expect( | ||
createKoa({ | ||
handlers: { | ||
http: () => true, | ||
ws: () => true | ||
}, | ||
path: '/', | ||
types: ['http'] | ||
}) | ||
).toBeDefined(); | ||
}); | ||
|
||
it('creates an WS interface', () => { | ||
expect( | ||
createKoa({ | ||
handlers: { | ||
http: () => true, | ||
ws: () => true | ||
}, | ||
path: '/', | ||
types: ['ws'] | ||
}).ws | ||
).toBeDefined(); | ||
}); | ||
|
||
it('creates an HTTP + WS interface', () => { | ||
expect( | ||
createKoa({ | ||
handlers: { | ||
http: () => true, | ||
ws: () => true | ||
}, | ||
path: '/', | ||
types: ['http', 'ws'] | ||
}) | ||
).toBeDefined(); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
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
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