forked from TypeFox/monaco-languageclient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
55 lines (53 loc) · 2.05 KB
/
main.ts
File metadata and controls
55 lines (53 loc) · 2.05 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2018-2022 TypeFox GmbH (http://www.typefox.io). All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import { WebSocketServer } from 'ws';
import { IncomingMessage } from 'http';
import { URL } from 'url';
import express from 'express';
import { getLocalDirectory } from '../../utils/fs-utils.js';
import { upgradeWsServer } from '../../common/server-commons.js';
export const runPythonServer = (baseDir: string, relativeDir: string) => {
process.on('uncaughtException', function(err: any) {
console.error('Uncaught Exception: ', err.toString());
if (err.stack) {
console.error(err.stack);
}
});
// create the express application
const app = express();
// server the static content, i.e. index.html
const dir = getLocalDirectory(import.meta.url);
app.use(express.static(dir));
// start the server
const server = app.listen(30001);
// create the web socket
const wss = new WebSocketServer({
noServer: true,
perMessageDeflate: false,
clientTracking: true,
verifyClient: (
clientInfo: { origin: string; secure: boolean; req: IncomingMessage },
callback
) => {
const parsedURL = new URL(`${clientInfo.origin}${clientInfo.req?.url ?? ''}`);
const authToken = parsedURL.searchParams.get('authorization');
if (authToken === 'UserAuth') {
// eslint-disable-next-line n/no-callback-literal
callback(true);
} else {
// eslint-disable-next-line n/no-callback-literal
callback(false);
}
}
});
upgradeWsServer({
serverName: 'PYRIGHT',
pathName: '/pyright',
server,
wss,
baseDir,
relativeDir
});
};