|
1 | 1 | import fs from "node:fs"; |
2 | 2 | import type { Server as HTTPServer } from "node:http"; |
3 | 3 | import path from "node:path"; |
4 | | -import { Plugin, toPlugin } from "../plugin"; |
5 | | -import type { BasePluginConfig, PluginPhase } from "shared"; |
6 | | -import { databricksClientMiddleware, isRemoteServerEnabled } from "../utils"; |
7 | 4 | import dotenv from "dotenv"; |
8 | 5 | import express from "express"; |
| 6 | +import type { PluginPhase } from "shared"; |
| 7 | +import { Plugin, toPlugin } from "../plugin"; |
| 8 | +import { instrumentations } from "../telemetry"; |
| 9 | +import { databricksClientMiddleware, isRemoteServerEnabled } from "../utils"; |
9 | 10 | import { DevModeManager } from "./dev-mode"; |
| 11 | +import type { ServerConfig } from "./types"; |
10 | 12 | import { getQueries, getRoutes } from "./utils"; |
11 | | -import { instrumentations } from "../telemetry"; |
12 | 13 |
|
13 | 14 | dotenv.config({ path: path.resolve(process.cwd(), "./server/.env") }); |
14 | 15 |
|
15 | | -export interface ServerConfig extends BasePluginConfig { |
16 | | - port?: number; |
17 | | - plugins?: Record<string, Plugin>; |
18 | | - staticPath?: string; |
19 | | - autoStart?: boolean; |
20 | | - host?: string; |
21 | | - watch?: boolean; |
22 | | -} |
23 | | - |
24 | 16 | export class ServerPlugin extends Plugin { |
25 | | - public name = "server" as const; |
26 | | - public envVars = ["DATABRICKS_APP_PORT", "FLASK_RUN_HOST"]; |
27 | 17 | public static DEFAULT_CONFIG = { |
28 | 18 | autoStart: true, |
29 | 19 | staticPath: path.resolve(process.cwd(), "client", "dist"), |
30 | 20 | host: process.env.FLASK_RUN_HOST || "0.0.0.0", |
31 | 21 | port: Number(process.env.DATABRICKS_APP_PORT) || 8000, |
32 | 22 | watch: process.env.NODE_ENV === "development", |
33 | 23 | }; |
| 24 | + |
| 25 | + public name = "server" as const; |
| 26 | + public envVars = ["DATABRICKS_APP_PORT", "FLASK_RUN_HOST"]; |
34 | 27 | private serverApplication: express.Application; |
35 | 28 | private server: HTTPServer | null; |
36 | 29 | private devModeManager?: DevModeManager; |
@@ -63,7 +56,7 @@ export class ServerPlugin extends Plugin { |
63 | 56 | } |
64 | 57 |
|
65 | 58 | shouldAutoStart() { |
66 | | - return this.config.autoStart ?? ServerPlugin.DEFAULT_CONFIG.autoStart; |
| 59 | + return this.config.autoStart; |
67 | 60 | } |
68 | 61 |
|
69 | 62 | isRemoteServingEnabled() { |
@@ -99,14 +92,10 @@ export class ServerPlugin extends Plugin { |
99 | 92 | } |
100 | 93 |
|
101 | 94 | const server = this.serverApplication.listen( |
102 | | - this.config.port || ServerPlugin.DEFAULT_CONFIG.port, |
103 | | - this.config.host || ServerPlugin.DEFAULT_CONFIG.host, |
| 95 | + this.config.port ?? ServerPlugin.DEFAULT_CONFIG.port, |
| 96 | + this.config.host ?? ServerPlugin.DEFAULT_CONFIG.host, |
104 | 97 | () => { |
105 | | - console.log( |
106 | | - `Server is running on port ${ |
107 | | - this.config.port || ServerPlugin.DEFAULT_CONFIG.port |
108 | | - }`, |
109 | | - ); |
| 98 | + console.log(`Server is running on port ${this.config.port}`); |
110 | 99 | if (this.config.staticPath && !this.config.watch) { |
111 | 100 | console.log(`Serving static files from: ${this.config.staticPath}`); |
112 | 101 | } |
|
0 commit comments