UNPKG

1.47 kBPlain TextView Raw
1import { commandLineOptions } from './command-line.ts';
2import * as http from 'http';
3import { createHTTPServer } from './http-server.ts';
4import * as WebSocket from 'ws';
5import { createWebSocketServer } from './ws-server.ts';
6import {
7 Clients,
8 CompiledFiles
9} from '../index.d.ts';
10import {
11 buildStatic
12} from './static-builder.ts';
13
14(async () => {
15 let clients: Clients = {};
16
17 let compiledFiles: CompiledFiles = {};
18
19 const httpServer: Readonly<http.Server> = await createHTTPServer({
20 wsPort: commandLineOptions.wsPort,
21 watchFiles: commandLineOptions.watchFiles,
22 jsTarget: commandLineOptions.jsTarget,
23 clients,
24 compiledFiles,
25 disableSpa: commandLineOptions.disableSpa,
26 customHTTPHeadersFilePath: commandLineOptions.customHTTPHeadersFilePath
27 });
28
29 const wsServer: Readonly<WebSocket.Server> | 'NOT_CREATED' = createWebSocketServer({
30 wsPort: commandLineOptions.wsPort,
31 watchFiles: commandLineOptions.watchFiles,
32 clients
33 });
34
35 httpServer.listen(commandLineOptions.httpPort);
36 console.log(`Zwitterion listening on port ${commandLineOptions.httpPort}`);
37 process.send && process.send('ZWITTERION_LISTENING');
38
39 if (commandLineOptions.buildStatic) {
40 buildStatic({
41 exclude: commandLineOptions.exclude,
42 include: commandLineOptions.include,
43 httpPort: commandLineOptions.httpPort
44 });
45 }
46})();