@vandenberghinc/volt 1.1.6 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/backend/dist/cjs/file_watcher.d.ts +0 -44
- package/backend/dist/cjs/file_watcher.js +324 -343
- package/backend/dist/cjs/server.d.ts +2 -5
- package/backend/dist/cjs/server.js +182 -179
- package/backend/dist/cjs/volt.d.ts +0 -1
- package/backend/dist/cjs/volt.js +1 -1
- package/backend/dist/esm/file_watcher.d.ts +1 -44
- package/backend/dist/esm/file_watcher.js +325 -309
- package/backend/dist/esm/server.d.ts +2 -5
- package/backend/dist/esm/server.js +182 -179
- package/backend/dist/esm/volt.d.ts +0 -1
- package/backend/dist/esm/volt.js +1 -1
- package/backend/dist/esm-dev/file_watcher.d.ts +1 -44
- package/backend/dist/esm-dev/file_watcher.js +325 -309
- package/backend/dist/esm-dev/server.d.ts +2 -5
- package/backend/dist/esm-dev/server.js +182 -179
- package/backend/dist/esm-dev/volt.d.ts +0 -1
- package/backend/dist/esm-dev/volt.js +1 -1
- package/backend/src/file_watcher.ts +324 -323
- package/backend/src/server.ts +107 -109
- package/backend/src/volt.ts +1 -1
- package/package.json +2 -3
|
@@ -7,7 +7,6 @@ import * as Mail from './plugins/mail.js';
|
|
|
7
7
|
import { Status } from "./status.js";
|
|
8
8
|
import { Endpoint, EndpointOptions } from "./endpoint.js";
|
|
9
9
|
import { Database, Collection } from "./database.js";
|
|
10
|
-
import { /*StaticFileWatcher,*/ FileWatcher } from "./file_watcher.js";
|
|
11
10
|
import { Users } from "./users.js";
|
|
12
11
|
import { Paddle } from "./payments/paddle.js";
|
|
13
12
|
import { RateLimits, RateLimitServer, RateLimitClient } from "./rate_limit.js";
|
|
@@ -121,7 +120,6 @@ export declare class Server {
|
|
|
121
120
|
additional_sitemap_endpoints: string[];
|
|
122
121
|
log_level: number;
|
|
123
122
|
tls?: TLSConfig;
|
|
124
|
-
file_watcher?: FileWatcher;
|
|
125
123
|
lightweight: boolean;
|
|
126
124
|
performance: vlib.Performance;
|
|
127
125
|
csp: Record<string, string>;
|
|
@@ -141,7 +139,6 @@ export declare class Server {
|
|
|
141
139
|
keys: Record<string, string>;
|
|
142
140
|
private _on_start;
|
|
143
141
|
private _on_stop;
|
|
144
|
-
is_file_watcher: boolean;
|
|
145
142
|
daemon?: vlib.Daemon;
|
|
146
143
|
private _stop_tscompiler_watcher?;
|
|
147
144
|
users: Users;
|
|
@@ -149,7 +146,8 @@ export declare class Server {
|
|
|
149
146
|
status: typeof Status;
|
|
150
147
|
rate_limits: typeof RateLimits;
|
|
151
148
|
logger: typeof logger;
|
|
152
|
-
constructor({ ip,
|
|
149
|
+
constructor({ ip, // leave undefined for blank detection.
|
|
150
|
+
port, domain, is_primary, source, database, statics, favicon, company, meta, tls, smtp, mail_style, rate_limit, keys, payments, default_headers, google_tag, token_expiration, enable_2fa, enable_account_activation, production, localhost, multiprocessing, processes, offline, additional_sitemap_endpoints, log_level, daemon, lightweight, }: {
|
|
153
151
|
ip?: string;
|
|
154
152
|
port?: number;
|
|
155
153
|
domain: string;
|
|
@@ -178,7 +176,6 @@ export declare class Server {
|
|
|
178
176
|
localhost?: boolean;
|
|
179
177
|
multiprocessing?: boolean;
|
|
180
178
|
processes?: number | null;
|
|
181
|
-
file_watcher?: FileWatcher | Record<string, any> | boolean;
|
|
182
179
|
offline?: boolean;
|
|
183
180
|
additional_sitemap_endpoints?: string[];
|
|
184
181
|
log_level?: number;
|
|
@@ -23,7 +23,7 @@ import { Endpoint } from "./endpoint.js";
|
|
|
23
23
|
import { ImageEndpoint } from "./image_endpoint.js";
|
|
24
24
|
import { Stream } from "./stream.js";
|
|
25
25
|
import { Database } from "./database.js";
|
|
26
|
-
import { /*StaticFileWatcher,*/ FileWatcher } from "./file_watcher.js";
|
|
26
|
+
// import { /*StaticFileWatcher,*/ FileWatcher } from "./file_watcher.js";
|
|
27
27
|
import { Users } from "./users.js";
|
|
28
28
|
import { Paddle } from "./payments/paddle.js";
|
|
29
29
|
import { RateLimits, RateLimitServer, RateLimitClient } from "./rate_limit.js";
|
|
@@ -680,7 +680,7 @@ export class Server {
|
|
|
680
680
|
additional_sitemap_endpoints;
|
|
681
681
|
log_level;
|
|
682
682
|
tls;
|
|
683
|
-
file_watcher;
|
|
683
|
+
// public file_watcher?: FileWatcher;
|
|
684
684
|
// public admin: AdminConfig;
|
|
685
685
|
// public ts: TypeScriptConfig;
|
|
686
686
|
lightweight;
|
|
@@ -704,7 +704,7 @@ export class Server {
|
|
|
704
704
|
_on_stop;
|
|
705
705
|
// public browser_preview?: BrowserPreview;
|
|
706
706
|
// public static_file_watcher: StaticFileWatcher;
|
|
707
|
-
is_file_watcher;
|
|
707
|
+
// public is_file_watcher: boolean;
|
|
708
708
|
daemon;
|
|
709
709
|
_stop_tscompiler_watcher;
|
|
710
710
|
users;
|
|
@@ -712,7 +712,8 @@ export class Server {
|
|
|
712
712
|
status;
|
|
713
713
|
rate_limits;
|
|
714
714
|
logger;
|
|
715
|
-
constructor({ ip
|
|
715
|
+
constructor({ ip, // leave undefined for blank detection.
|
|
716
|
+
port = 8000, domain, is_primary = true, source, database = "mongodb://localhost:27017/main", statics = [], favicon = undefined, company, meta = new Meta(), tls = undefined, smtp = undefined, mail_style = {
|
|
716
717
|
font: '"Helvetica", sans-serif',
|
|
717
718
|
title_fg: "#121B23",
|
|
718
719
|
subtitle_fg: "#121B23",
|
|
@@ -737,7 +738,9 @@ export class Server {
|
|
|
737
738
|
},
|
|
738
739
|
}, keys = [], payments = null, default_headers = null, google_tag = undefined, token_expiration = 86400, enable_2fa = false, enable_account_activation = true,
|
|
739
740
|
// honey_pot_key = null,
|
|
740
|
-
production = false, localhost = true, multiprocessing = true, processes = null,
|
|
741
|
+
production = false, localhost = true, multiprocessing = true, processes = null,
|
|
742
|
+
// file_watcher = false,
|
|
743
|
+
offline = false, additional_sitemap_endpoints = [], log_level = 0, daemon = {},
|
|
741
744
|
// admin = {
|
|
742
745
|
// password: null,
|
|
743
746
|
// ips: [],
|
|
@@ -870,7 +873,7 @@ export class Server {
|
|
|
870
873
|
localhost: { type: "boolean", required: false },
|
|
871
874
|
multiprocessing: { type: "boolean", required: false, default: true },
|
|
872
875
|
processes: { type: "number", required: false, default: null },
|
|
873
|
-
file_watcher: {
|
|
876
|
+
// file_watcher: {type: ["null", "boolean", "object", FileWatcher], required: false},
|
|
874
877
|
offline: { type: "boolean", default: false },
|
|
875
878
|
additional_sitemap_endpoints: { type: "array", default: [] },
|
|
876
879
|
log_level: { type: "number", default: 0 },
|
|
@@ -895,7 +898,7 @@ export class Server {
|
|
|
895
898
|
} });
|
|
896
899
|
// Assign attributes directly.
|
|
897
900
|
this.port = port;
|
|
898
|
-
this.ip = ip;
|
|
901
|
+
this.ip = ip ?? "127.0.0.1";
|
|
899
902
|
this.is_primary = is_primary && libcluster.isPrimary;
|
|
900
903
|
this.source = new vlib.Path(source);
|
|
901
904
|
this.favicon = favicon;
|
|
@@ -927,6 +930,10 @@ export class Server {
|
|
|
927
930
|
this.ip = "127.0.0.1";
|
|
928
931
|
this.domain = this.ip + ":" + (port + (this.tls ? 1 : 0));
|
|
929
932
|
}
|
|
933
|
+
else if (!localhost && ip == null) { // use argument ip not attr since that already has a default.
|
|
934
|
+
this.ip = vlib.Network.private_ip();
|
|
935
|
+
this.domain = this.ip + ":" + (port + (this.tls ? 1 : 0));
|
|
936
|
+
}
|
|
930
937
|
/* @performance */ this.performance = new vlib.Performance("Server performance");
|
|
931
938
|
// Assign objects to server so it is easy to access.
|
|
932
939
|
this.status = Status;
|
|
@@ -1035,96 +1042,98 @@ export class Server {
|
|
|
1035
1042
|
// Static file watcher.
|
|
1036
1043
|
// this.static_file_watcher = new StaticFileWatcher(this);
|
|
1037
1044
|
// Initialize file watcher.
|
|
1038
|
-
if (file_watcher !== false) {
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1045
|
+
// if (file_watcher !== false) {
|
|
1046
|
+
// console.warn("[Volt] Argument file_watcher is deprecated. This may be removed in future versions.");
|
|
1047
|
+
// if (file_watcher == null) {
|
|
1048
|
+
// // Null.
|
|
1049
|
+
// file_watcher = {};
|
|
1050
|
+
// }
|
|
1051
|
+
// if (!(file_watcher as Record<string, any>).source) {
|
|
1052
|
+
// // Source.
|
|
1053
|
+
// (file_watcher as Record<string, any>).source = this.source.str();
|
|
1054
|
+
// }
|
|
1055
|
+
// if (!(file_watcher instanceof FileWatcher)) {
|
|
1056
|
+
// // Initialize.
|
|
1057
|
+
// file_watcher = new FileWatcher(file_watcher as any);
|
|
1058
|
+
// }
|
|
1059
|
+
// this.file_watcher = file_watcher as FileWatcher;
|
|
1060
|
+
// }
|
|
1061
|
+
// else {
|
|
1062
|
+
// this.file_watcher = undefined;
|
|
1063
|
+
// }
|
|
1064
|
+
// File watcher.
|
|
1065
|
+
// if (
|
|
1066
|
+
// process.env.VOLT_NO_FILE_WATCHER == null &&
|
|
1067
|
+
// !process.argv.includes("--no-file-watcher") &&
|
|
1068
|
+
// this.production === false &&
|
|
1069
|
+
// // file_watcher !== false &&
|
|
1070
|
+
// process.env.VOLT_FILE_WATCHER !== '1'
|
|
1071
|
+
// ) {
|
|
1072
|
+
// // Disable primary for when users access is_primary.
|
|
1073
|
+
// this.is_primary = false;
|
|
1074
|
+
// // Enable file watcher.
|
|
1075
|
+
// this.is_file_watcher = true;
|
|
1076
|
+
// }
|
|
1077
|
+
// // No file watcher.
|
|
1078
|
+
// else {
|
|
1079
|
+
// Disable file watcher.
|
|
1080
|
+
// this.is_file_watcher = false;
|
|
1081
|
+
// Set logger.
|
|
1082
|
+
logger.log_level = this.log_level;
|
|
1083
|
+
this.log = logger.log.bind(logger);
|
|
1084
|
+
this.error = logger.error.bind(logger);
|
|
1085
|
+
// Initialize the service daemon.
|
|
1086
|
+
// Must be initialized before initializing the database.
|
|
1087
|
+
if (daemon !== false) {
|
|
1088
|
+
const log_source = this.source.join(".logs");
|
|
1089
|
+
if (!log_source.exists()) {
|
|
1090
|
+
log_source.mkdir_sync();
|
|
1051
1091
|
}
|
|
1052
|
-
this.
|
|
1092
|
+
this.daemon = new vlib.Daemon({
|
|
1093
|
+
name: this.domain.replaceAll(".", ""),
|
|
1094
|
+
user: daemon.user || os.userInfo().username,
|
|
1095
|
+
group: daemon.group || null,
|
|
1096
|
+
command: "volt --service --start",
|
|
1097
|
+
cwd: this.source.str(),
|
|
1098
|
+
args: daemon.args || [],
|
|
1099
|
+
env: daemon.env || {},
|
|
1100
|
+
description: daemon.description || `Service daemon for website ${this.domain}.`,
|
|
1101
|
+
auto_restart: true,
|
|
1102
|
+
logs: daemon.logs || log_source.join("logs").str(),
|
|
1103
|
+
errors: daemon.errors || log_source.join("errors").str(),
|
|
1104
|
+
});
|
|
1053
1105
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1106
|
+
// Initialize the database class.
|
|
1107
|
+
if (typeof database === "string") {
|
|
1108
|
+
this.db = new Database({ uri: database, _server: this });
|
|
1056
1109
|
}
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
this.
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
this.is_file_watcher = false;
|
|
1072
|
-
// Set logger.
|
|
1073
|
-
logger.log_level = this.log_level;
|
|
1074
|
-
this.log = logger.log.bind(logger);
|
|
1075
|
-
this.error = logger.error.bind(logger);
|
|
1076
|
-
// Initialize the service daemon.
|
|
1077
|
-
// Must be initialized before initializing the database.
|
|
1078
|
-
if (daemon !== false) {
|
|
1079
|
-
const log_source = this.source.join(".logs");
|
|
1080
|
-
if (!log_source.exists()) {
|
|
1081
|
-
log_source.mkdir_sync();
|
|
1082
|
-
}
|
|
1083
|
-
this.daemon = new vlib.Daemon({
|
|
1084
|
-
name: this.domain.replaceAll(".", ""),
|
|
1085
|
-
user: daemon.user || os.userInfo().username,
|
|
1086
|
-
group: daemon.group || null,
|
|
1087
|
-
command: "volt --service --start",
|
|
1088
|
-
cwd: this.source.str(),
|
|
1089
|
-
args: daemon.args || [],
|
|
1090
|
-
env: daemon.env || {},
|
|
1091
|
-
description: daemon.description || `Service daemon for website ${this.domain}.`,
|
|
1092
|
-
auto_restart: true,
|
|
1093
|
-
logs: daemon.logs || log_source.join("logs").str(),
|
|
1094
|
-
errors: daemon.errors || log_source.join("errors").str(),
|
|
1095
|
-
});
|
|
1096
|
-
}
|
|
1097
|
-
// Initialize the database class.
|
|
1098
|
-
if (typeof database === "string") {
|
|
1099
|
-
this.db = new Database({ uri: database, _server: this });
|
|
1100
|
-
}
|
|
1101
|
-
else if (database !== false) {
|
|
1102
|
-
this.db = new Database({ ...database, _server: this });
|
|
1103
|
-
}
|
|
1104
|
-
// Initialize the users class.
|
|
1105
|
-
this.users = new Users(this);
|
|
1106
|
-
// The smtp instance.
|
|
1107
|
-
if (smtp) {
|
|
1108
|
-
this.smtp_sender = smtp.sender;
|
|
1109
|
-
this.smtp = nodemailer.createTransport(smtp);
|
|
1110
|
+
else if (database !== false) {
|
|
1111
|
+
this.db = new Database({ ...database, _server: this });
|
|
1112
|
+
}
|
|
1113
|
+
// Initialize the users class.
|
|
1114
|
+
this.users = new Users(this);
|
|
1115
|
+
// The smtp instance.
|
|
1116
|
+
if (smtp) {
|
|
1117
|
+
this.smtp_sender = smtp.sender;
|
|
1118
|
+
this.smtp = nodemailer.createTransport(smtp);
|
|
1119
|
+
}
|
|
1120
|
+
// The rate limit server/client.
|
|
1121
|
+
if (rate_limit) {
|
|
1122
|
+
if (this.is_primary) {
|
|
1123
|
+
this.rate_limit = new RateLimitServer({ ...(rate_limit.server ?? {}), _server: this });
|
|
1110
1124
|
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
this.rate_limit = new RateLimitServer({ ...(rate_limit.server ?? {}), _server: this });
|
|
1115
|
-
}
|
|
1116
|
-
else {
|
|
1117
|
-
if (rate_limit.server?.https) {
|
|
1118
|
-
rate_limit.client.https = true;
|
|
1119
|
-
}
|
|
1120
|
-
this.rate_limit = new RateLimitClient({ ...(rate_limit.client ?? {}), _server: this });
|
|
1125
|
+
else {
|
|
1126
|
+
if (rate_limit.server?.https) {
|
|
1127
|
+
rate_limit.client.https = true;
|
|
1121
1128
|
}
|
|
1129
|
+
this.rate_limit = new RateLimitClient({ ...(rate_limit.client ?? {}), _server: this });
|
|
1122
1130
|
}
|
|
1123
|
-
// Blacklist class.
|
|
1124
|
-
// if (this.honey_pot_key) {
|
|
1125
|
-
// this.blacklist = new Blacklist({api_key: this.honey_pot_key});
|
|
1126
|
-
// }
|
|
1127
1131
|
}
|
|
1132
|
+
// Blacklist class.
|
|
1133
|
+
// if (this.honey_pot_key) {
|
|
1134
|
+
// this.blacklist = new Blacklist({api_key: this.honey_pot_key});
|
|
1135
|
+
// }
|
|
1136
|
+
// }
|
|
1128
1137
|
// Other keys.
|
|
1129
1138
|
this.keys = {};
|
|
1130
1139
|
// Start callbacks.
|
|
@@ -1215,7 +1224,7 @@ export class Server {
|
|
|
1215
1224
|
// Create default endpoints.
|
|
1216
1225
|
_create_default_endpoints() {
|
|
1217
1226
|
// Vars.
|
|
1218
|
-
const additional_file_watcher_paths = [];
|
|
1227
|
+
// const additional_file_watcher_paths: string[] = [];
|
|
1219
1228
|
// Add favicon.
|
|
1220
1229
|
if (this.favicon != null) {
|
|
1221
1230
|
const favicon = new vlib.Path(this.favicon);
|
|
@@ -1323,7 +1332,7 @@ export class Server {
|
|
|
1323
1332
|
._load_data_by_path(this));
|
|
1324
1333
|
});
|
|
1325
1334
|
// Handler.
|
|
1326
|
-
return additional_file_watcher_paths;
|
|
1335
|
+
// return additional_file_watcher_paths;
|
|
1327
1336
|
}
|
|
1328
1337
|
// Create the sitemap endpoint.
|
|
1329
1338
|
_create_sitemap() {
|
|
@@ -1693,87 +1702,81 @@ export class Server {
|
|
|
1693
1702
|
logger.log(1, log_source, "Initializing server.");
|
|
1694
1703
|
/* @performance */ this.performance.start();
|
|
1695
1704
|
// File watcher.
|
|
1696
|
-
if (this.is_file_watcher) {
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1705
|
+
// if (this.is_file_watcher) {
|
|
1706
|
+
// // Disable primary for when users access is_primary.
|
|
1707
|
+
// this.is_primary = false;
|
|
1708
|
+
// // Create default endpoints for excluded static file watch paths.
|
|
1709
|
+
// this._create_default_endpoints();
|
|
1710
|
+
// // Exclude the typescript output directory from the file watcher.
|
|
1711
|
+
// // if (this.ts.output) {
|
|
1712
|
+
// // this.file_watcher!.add_exclude(this.ts.output);
|
|
1713
|
+
// // }
|
|
1714
|
+
// // Add the volt backend source files to the additional files.
|
|
1715
|
+
// this.file_watcher!.add_path(__dirname);
|
|
1716
|
+
// this.file_watcher!.add_exclude(`${__dirname}/frontend_globals.js`);
|
|
1717
|
+
// // Exclude static files.
|
|
1718
|
+
// this.statics.forEach(item => {
|
|
1719
|
+
// if (typeof item === "string" || item instanceof vlib.Path) {
|
|
1720
|
+
// this.file_watcher!.add_exclude(item);
|
|
1721
|
+
// }
|
|
1722
|
+
// else {
|
|
1723
|
+
// this.file_watcher!.add_exclude(item.path)
|
|
1724
|
+
// }
|
|
1725
|
+
// })
|
|
1726
|
+
// if (!this.production) {
|
|
1727
|
+
// [
|
|
1728
|
+
// `${process.env.PERSISTANCE}/private/dev/vinc/vlib/js/vlib.js`,
|
|
1729
|
+
// `${process.env.PERSISTANCE}/private/dev/vinc/vhighlight/vhighlight.js`,
|
|
1730
|
+
// ].forEach(path => {
|
|
1731
|
+
// const vpath = new vlib.Path(path);
|
|
1732
|
+
// if (vpath.exists()) {
|
|
1733
|
+
// this.file_watcher!.add_exclude(vpath.str());
|
|
1734
|
+
// }
|
|
1735
|
+
// })
|
|
1736
|
+
// }
|
|
1737
|
+
// // Stop.
|
|
1738
|
+
// return;
|
|
1739
|
+
// }
|
|
1740
|
+
// // No file watcher.
|
|
1741
|
+
// else {
|
|
1742
|
+
// Create HTTPS server.
|
|
1743
|
+
if (this.tls) {
|
|
1744
|
+
this.https = http2.createSecureServer({
|
|
1745
|
+
key: new vlib.Path(this.tls.key).load_sync({ encoding: 'utf8' }),
|
|
1746
|
+
cert: new vlib.Path(this.tls.cert).load_sync({ encoding: 'utf8' }),
|
|
1747
|
+
ca: this.tls.ca == null ? null : new vlib.Path(this.tls.ca).load_sync({ encoding: 'utf8' }),
|
|
1748
|
+
passphrase: this.tls.passphrase,
|
|
1749
|
+
allowHTTP1: true,
|
|
1750
|
+
},
|
|
1751
|
+
// Support for http1.
|
|
1752
|
+
// Does not work, requests get triggered on the stream and on this callback.
|
|
1753
|
+
(req, res) => {
|
|
1754
|
+
if (req.httpVersion.charAt(0) !== "2") {
|
|
1755
|
+
this._serve(undefined, undefined, req, res);
|
|
1719
1756
|
}
|
|
1720
1757
|
});
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1758
|
+
this.https.on('stream', (stream, headers) => {
|
|
1759
|
+
this._serve(stream, headers, undefined, undefined);
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
// Payments require HTTPS in production.
|
|
1763
|
+
else if (this.production && this.payments) {
|
|
1764
|
+
throw Error("Accepting payments in production mode requires HTTPS.");
|
|
1765
|
+
}
|
|
1766
|
+
// Redirect HTTP requests to HTTPS.
|
|
1767
|
+
if (this.tls) {
|
|
1768
|
+
this.http = http.createServer((request, response) => {
|
|
1769
|
+
response.writeHead(301, { Location: `https://${request.headers.host}${request.url}` });
|
|
1770
|
+
response.end();
|
|
1771
|
+
});
|
|
1734
1772
|
}
|
|
1735
|
-
// No file watcher.
|
|
1736
1773
|
else {
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
key: new vlib.Path(this.tls.key).load_sync({ encoding: 'utf8' }),
|
|
1741
|
-
cert: new vlib.Path(this.tls.cert).load_sync({ encoding: 'utf8' }),
|
|
1742
|
-
ca: this.tls.ca == null ? null : new vlib.Path(this.tls.ca).load_sync({ encoding: 'utf8' }),
|
|
1743
|
-
passphrase: this.tls.passphrase,
|
|
1744
|
-
allowHTTP1: true,
|
|
1745
|
-
},
|
|
1746
|
-
// Support for http1.
|
|
1747
|
-
// Does not work, requests get triggered on the stream and on this callback.
|
|
1748
|
-
(req, res) => {
|
|
1749
|
-
if (req.httpVersion.charAt(0) !== "2") {
|
|
1750
|
-
this._serve(undefined, undefined, req, res);
|
|
1751
|
-
}
|
|
1752
|
-
});
|
|
1753
|
-
this.https.on('stream', (stream, headers) => {
|
|
1754
|
-
this._serve(stream, headers, undefined, undefined);
|
|
1755
|
-
});
|
|
1756
|
-
}
|
|
1757
|
-
// Payments require HTTPS in production.
|
|
1758
|
-
else if (this.production && this.payments) {
|
|
1759
|
-
throw Error("Accepting payments in production mode requires HTTPS.");
|
|
1760
|
-
}
|
|
1761
|
-
// Redirect HTTP requests to HTTPS.
|
|
1762
|
-
if (this.tls) {
|
|
1763
|
-
this.http = http.createServer((request, response) => {
|
|
1764
|
-
response.writeHead(301, { Location: `https://${request.headers.host}${request.url}` });
|
|
1765
|
-
response.end();
|
|
1766
|
-
});
|
|
1767
|
-
}
|
|
1768
|
-
else {
|
|
1769
|
-
this.http = http.createServer((req, res) => {
|
|
1770
|
-
this._serve(undefined, undefined, req, res);
|
|
1771
|
-
});
|
|
1772
|
-
}
|
|
1773
|
-
/* @performance */ this.performance.end("create-http-server");
|
|
1774
|
+
this.http = http.createServer((req, res) => {
|
|
1775
|
+
this._serve(undefined, undefined, req, res);
|
|
1776
|
+
});
|
|
1774
1777
|
}
|
|
1775
|
-
|
|
1776
|
-
|
|
1778
|
+
/* @performance */ this.performance.end("create-http-server");
|
|
1779
|
+
// }
|
|
1777
1780
|
// Start the database.
|
|
1778
1781
|
if (this.db) {
|
|
1779
1782
|
await this.db.initialize();
|
|
@@ -2109,11 +2112,11 @@ export class Server {
|
|
|
2109
2112
|
// Always initialize, even when forking.
|
|
2110
2113
|
await this.initialize();
|
|
2111
2114
|
// Inside file watcher process.
|
|
2112
|
-
if (this.is_file_watcher) {
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
}
|
|
2115
|
+
// if (this.is_file_watcher) {
|
|
2116
|
+
// this.file_watcher!.start();
|
|
2117
|
+
// await this.file_watcher!.promise;
|
|
2118
|
+
// return ;
|
|
2119
|
+
// }
|
|
2117
2120
|
// Start static file watcher.
|
|
2118
2121
|
// if (!this.production && this.file_watcher) {
|
|
2119
2122
|
// this.static_file_watcher.start();
|
|
@@ -2566,12 +2569,12 @@ export class Server {
|
|
|
2566
2569
|
}
|
|
2567
2570
|
// Add endpoint.
|
|
2568
2571
|
this.endpoints.set(`${endpoint.endpoint}:${endpoint.method}`, endpoint);
|
|
2569
|
-
if (!this.production) {
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
}
|
|
2572
|
+
// if (!this.production) {
|
|
2573
|
+
// if (endpoint._path && this.file_watcher?.add_exclude) {
|
|
2574
|
+
// this.file_watcher!.add_exclude(endpoint._path);
|
|
2575
|
+
// }
|
|
2576
|
+
// // this.static_file_watcher.add(endpoint);
|
|
2577
|
+
// }
|
|
2575
2578
|
}
|
|
2576
2579
|
return this;
|
|
2577
2580
|
}
|
|
@@ -9,7 +9,6 @@ export * from "./server.js";
|
|
|
9
9
|
export * from "./database.js";
|
|
10
10
|
export * from "./rate_limit.js";
|
|
11
11
|
export * from "./logger.js";
|
|
12
|
-
export * from "./file_watcher.js";
|
|
13
12
|
export * as Mail from "./plugins/mail.js";
|
|
14
13
|
export * as TypeScript from "./plugins/ts/compiler.js";
|
|
15
14
|
export * from "./plugins/css.js";
|
|
@@ -16,7 +16,7 @@ export * from "./server.js";
|
|
|
16
16
|
export * from "./database.js";
|
|
17
17
|
export * from "./rate_limit.js";
|
|
18
18
|
export * from "./logger.js";
|
|
19
|
-
export * from "./file_watcher.js"
|
|
19
|
+
// export * from "./file_watcher.js"
|
|
20
20
|
export * as Mail from "./plugins/mail.js";
|
|
21
21
|
// export * as PDF from "./plugins/pdf.js"
|
|
22
22
|
export * as TypeScript from "./plugins/ts/compiler.js";
|