@solid/community-server
Version:
Community Solid Server: an open and modular implementation of the Solid specifications
32 lines • 1.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateWebSocketUrl = generateWebSocketUrl;
exports.parseWebSocketRequest = parseWebSocketRequest;
const BadRequestHttpError_1 = require("../../../util/errors/BadRequestHttpError");
/**
* Generates a WebSocket URL by converting an HTTP(S) URL into a WS(S) URL.
*
* @param id - The identifier of the channel. Needs to be a URL.
*/
function generateWebSocketUrl(id) {
return `ws${id.slice('http'.length)}`;
}
/**
* Parses a {@link IncomingMessage} to extract its path used for authentication.
*
* @param baseUrl - The base URL of the server.
* @param request - The request to parse.
*/
function parseWebSocketRequest(baseUrl, request) {
const path = request.url;
if (!path) {
throw new BadRequestHttpError_1.BadRequestHttpError('Missing url parameter in WebSocket request');
}
// Use dummy base and then explicitly set the host and protocol from the base URL.
const id = new URL(path, 'http://example.com');
const base = new URL(baseUrl);
id.host = base.host;
id.protocol = base.protocol;
return id.href;
}
//# sourceMappingURL=WebSocket2023Util.js.map