Allow observation of routes for websockets, too
This commit is contained in:
parent
4d634c78be
commit
018a2bd399
|
@ -58,14 +58,19 @@ function _server(host, port, httpsOptions) {
|
||||||
const requestHandlerMap = {};
|
const requestHandlerMap = {};
|
||||||
const wsHandlerMap = {};
|
const wsHandlerMap = {};
|
||||||
|
|
||||||
|
function isPathPattern(p) {
|
||||||
|
// Loose, but good enough for distinguishing
|
||||||
|
// List-of-constants-and-captures from just a straight capture.
|
||||||
|
// TODO: Still really not the best idea. Reconsider schema.
|
||||||
|
return typeof p === 'object' && p !== null && typeof p.toJS === 'function';
|
||||||
|
}
|
||||||
|
|
||||||
function encodePath(path) {
|
function encodePath(path) {
|
||||||
return JSON.stringify(path.toJS().map((s) => Capture.isClassOf(s) ? null : s));
|
return JSON.stringify(path.toJS().map((s) => Capture.isClassOf(s) ? null : s));
|
||||||
}
|
}
|
||||||
|
|
||||||
during Observe(Request(_, server, $method, $pathPattern, _, _)) {
|
during Observe(Request(_, server, $method, $pathPattern, _, _)) {
|
||||||
if (typeof method !== 'string' ||
|
if (typeof method !== 'string' || !isPathPattern(pathPattern)) {
|
||||||
(typeof pathPattern !== 'object' || pathPattern === null ||
|
|
||||||
typeof pathPattern.toJS !== 'function')) {
|
|
||||||
// Likely some kind of logging observer.
|
// Likely some kind of logging observer.
|
||||||
// TODO: reconsider schema
|
// TODO: reconsider schema
|
||||||
return;
|
return;
|
||||||
|
@ -89,6 +94,11 @@ function _server(host, port, httpsOptions) {
|
||||||
}
|
}
|
||||||
|
|
||||||
during Observe(WebSocket(_, server, $pathPattern, _)) {
|
during Observe(WebSocket(_, server, $pathPattern, _)) {
|
||||||
|
if (!isPathPattern(pathPattern)) {
|
||||||
|
// Likely some kind of logging observer.
|
||||||
|
// TODO: reconsider schema
|
||||||
|
return;
|
||||||
|
}
|
||||||
const path = encodePath(pathPattern);
|
const path = encodePath(pathPattern);
|
||||||
on start {
|
on start {
|
||||||
if (!(path in wsHandlerMap)) wsHandlerMap[path] = {_count: 0, _path: pathPattern};
|
if (!(path in wsHandlerMap)) wsHandlerMap[path] = {_count: 0, _path: pathPattern};
|
||||||
|
|
Loading…
Reference in New Issue