vatts 1.3.0 → 1.3.1-alpha.1
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/dist/bin/vatts.js +0 -17
- package/dist/helpers.d.ts +3 -3
- package/dist/helpers.js +38 -26
- package/dist/index.js +2 -2
- package/dist/types.d.ts +7 -7
- package/package.json +1 -1
package/dist/bin/vatts.js
CHANGED
|
@@ -39,24 +39,7 @@ function initializeApp(options, isDev) {
|
|
|
39
39
|
port: options.port,
|
|
40
40
|
hostname: options.hostname,
|
|
41
41
|
framework: 'native',
|
|
42
|
-
ssl: null,
|
|
43
42
|
};
|
|
44
|
-
if (options.ssl) {
|
|
45
|
-
const sslDir = path.resolve(process.cwd(), 'certs');
|
|
46
|
-
const keyPath = path.join(sslDir, 'key.pem');
|
|
47
|
-
const certPath = path.join(sslDir, 'cert.pem');
|
|
48
|
-
if (fs.existsSync(keyPath) && fs.existsSync(certPath)) {
|
|
49
|
-
appOptions.ssl = {
|
|
50
|
-
key: keyPath,
|
|
51
|
-
cert: certPath
|
|
52
|
-
};
|
|
53
|
-
appOptions.ssl.redirectPort = options.httpRedirectPort || 80;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
Console.error(`SSL Error: Ensure that './certs/key.pem' and './certs/cert.pem' exist.`);
|
|
57
|
-
process.exit(1);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
43
|
const helperModule = require("../helpers");
|
|
61
44
|
const helper = helperModule.default(appOptions);
|
|
62
45
|
helper.init();
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import http, { Server } from 'http';
|
|
3
3
|
import type { VattsOptions, VattsConfig } from './types';
|
|
4
|
-
import
|
|
4
|
+
import http2 from 'http2';
|
|
5
5
|
/**
|
|
6
6
|
* Carrega o arquivo de configuração vatts.config.ts ou vatts.config.js do projeto
|
|
7
7
|
* @param projectDir Diretório raiz do projeto
|
|
@@ -18,9 +18,9 @@ export declare function app(options?: VattsOptions): {
|
|
|
18
18
|
*/
|
|
19
19
|
integrate: (serverApp: any) => Promise<any>;
|
|
20
20
|
/**
|
|
21
|
-
|
|
21
|
+
* Inicia um servidor Vatts.js fechado (o usuário não tem acesso ao framework)
|
|
22
22
|
*/
|
|
23
|
-
init: () => Promise<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> |
|
|
23
|
+
init: () => Promise<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | http2.Http2SecureServer<typeof http.IncomingMessage, typeof http.ServerResponse, typeof http2.Http2ServerRequest, typeof http2.Http2ServerResponse>>;
|
|
24
24
|
prepare: () => Promise<void>;
|
|
25
25
|
getRequestHandler: () => (req: any, res: any, next?: any) => Promise<void> | void;
|
|
26
26
|
setupWebSocket: (server: Server | any) => void;
|
package/dist/helpers.js
CHANGED
|
@@ -65,8 +65,8 @@ const path_1 = __importDefault(require("path"));
|
|
|
65
65
|
// Helpers para integração com diferentes frameworks
|
|
66
66
|
const index_js_1 = __importStar(require("./index.js")); // Importando o tipo
|
|
67
67
|
const console_1 = __importStar(require("./api/console"));
|
|
68
|
-
const
|
|
69
|
-
const fs_1 = __importDefault(require("fs"));
|
|
68
|
+
const http2_1 = __importDefault(require("http2")); // <-- ADICIONADO: Import do HTTP/2
|
|
69
|
+
const fs_1 = __importDefault(require("fs"));
|
|
70
70
|
// Registra loaders customizados para importar arquivos não-JS
|
|
71
71
|
const { registerLoaders } = require('./loaders');
|
|
72
72
|
registerLoaders({ projectDir: process.cwd() });
|
|
@@ -90,7 +90,8 @@ function getLocalExternalIp() {
|
|
|
90
90
|
}
|
|
91
91
|
const sendBox = (options) => {
|
|
92
92
|
const isDev = options.dev;
|
|
93
|
-
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
const isSSL = exports.config.ssl && exports.config.ssl.key && exports.config.ssl.cert;
|
|
94
95
|
const protocol = isSSL ? 'https' : 'http';
|
|
95
96
|
const localIp = getLocalExternalIp();
|
|
96
97
|
// Estilos Clean
|
|
@@ -104,14 +105,16 @@ const sendBox = (options) => {
|
|
|
104
105
|
console.log(timer + labelStyle + ' Access on:');
|
|
105
106
|
console.log(' ');
|
|
106
107
|
// 1. Local (Alinhamento: Local tem 6 letras + 4 espaços = 10)
|
|
107
|
-
console.info(timer + `${labelStyle} ┃ Local:${console_1.Colors.Reset} ${urlStyle}${protocol}://localhost:${
|
|
108
|
+
console.info(timer + `${labelStyle} ┃ Local:${console_1.Colors.Reset} ${urlStyle}${protocol}://localhost:${exports.config?.port}${console_1.Colors.Reset}`);
|
|
108
109
|
// 2. Network (Alinhamento: Network tem 8 letras + 2 espaços = 10)
|
|
109
110
|
if (localIp) {
|
|
110
|
-
console.info(timer + `${labelStyle} ┃ Network:${console_1.Colors.Reset} ${urlStyle}${protocol}://${localIp}:${
|
|
111
|
+
console.info(timer + `${labelStyle} ┃ Network:${console_1.Colors.Reset} ${urlStyle}${protocol}://${localIp}:${exports.config?.port}${console_1.Colors.Reset}`);
|
|
111
112
|
}
|
|
112
113
|
// 3. Infos Extras (Redirect HTTP -> HTTPS)
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
// @ts-ignore
|
|
115
|
+
if (isSSL && exports.config.ssl?.redirectPort) {
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
console.info(timer + `${labelStyle} ┃ Redirect:${console_1.Colors.Reset} ${labelStyle}port ${exports.config.ssl.redirectPort} ➜ https${console_1.Colors.Reset}`);
|
|
115
118
|
}
|
|
116
119
|
// 4. Info de Ambiente
|
|
117
120
|
if (isDev) {
|
|
@@ -136,7 +139,8 @@ async function loadVattsConfig(projectDir, phase) {
|
|
|
136
139
|
maxUrlLength: 2048,
|
|
137
140
|
accessLogging: true,
|
|
138
141
|
envFiles: [],
|
|
139
|
-
pathRouter: false
|
|
142
|
+
pathRouter: false,
|
|
143
|
+
port: 3000
|
|
140
144
|
};
|
|
141
145
|
try {
|
|
142
146
|
// Tenta primeiro .ts, depois .js
|
|
@@ -246,7 +250,7 @@ function applyCors(req, res, corsConfig) {
|
|
|
246
250
|
}
|
|
247
251
|
/**
|
|
248
252
|
* Middleware para parsing do body com proteções de segurança (versão melhorada).
|
|
249
|
-
*/
|
|
253
|
+
*/
|
|
250
254
|
const parseBody = (req) => {
|
|
251
255
|
// Constantes para limites de segurança
|
|
252
256
|
const MAX_BODY_SIZE = 10 * 1024 * 1024; // 10MB limite total
|
|
@@ -331,7 +335,7 @@ async function initNativeServer(vattsApp, options, port, hostname) {
|
|
|
331
335
|
options.envFiles = vattsConfig.envFiles;
|
|
332
336
|
await vattsApp.prepare();
|
|
333
337
|
const handler = vattsApp.getRequestHandler();
|
|
334
|
-
const msg = console_1.default.dynamicLine(`${console_1.Colors.Bright}Starting Vatts.js on port ${
|
|
338
|
+
const msg = console_1.default.dynamicLine(`${console_1.Colors.Bright}Starting Vatts.js on port ${exports.config?.port}${console_1.Colors.Reset}`);
|
|
335
339
|
// --- LÓGICA DO LISTENER (REUTILIZÁVEL) ---
|
|
336
340
|
// Extraímos a lógica principal para uma variável
|
|
337
341
|
// para que possa ser usada tanto pelo servidor HTTP quanto HTTPS.
|
|
@@ -461,18 +465,20 @@ async function initNativeServer(vattsApp, options, port, hostname) {
|
|
|
461
465
|
}
|
|
462
466
|
};
|
|
463
467
|
// --- FIM DO LISTENER ---
|
|
464
|
-
let server; //
|
|
465
|
-
const isSSL =
|
|
466
|
-
if (isSSL &&
|
|
468
|
+
let server; // <-- ADICIONADO: Suporte a Http2SecureServer
|
|
469
|
+
const isSSL = exports.config.ssl && exports.config.ssl.key && exports.config.ssl.cert;
|
|
470
|
+
if (isSSL && exports.config.ssl) {
|
|
467
471
|
const sslOptions = {
|
|
468
|
-
key: fs_1.default.readFileSync(
|
|
469
|
-
cert: fs_1.default.readFileSync(
|
|
470
|
-
ca:
|
|
472
|
+
key: fs_1.default.readFileSync(exports.config.ssl.key, 'utf8'),
|
|
473
|
+
cert: fs_1.default.readFileSync(exports.config.ssl.cert, 'utf8'),
|
|
474
|
+
ca: exports.config.ssl.ca ? fs_1.default.readFileSync(exports.config.ssl.ca, 'utf8') : undefined,
|
|
475
|
+
allowHTTP1: true // <-- IMPORTANTE: Garante compatibilidade com clientes HTTP/1.1
|
|
471
476
|
};
|
|
472
|
-
// 1. Cria o servidor HTTPS
|
|
473
|
-
|
|
477
|
+
// 1. Cria o servidor HTTPS com HTTP/2
|
|
478
|
+
// Substituído https.createServer por http2.createSecureServer
|
|
479
|
+
server = http2_1.default.createSecureServer(sslOptions, requestListener);
|
|
474
480
|
// 2. Cria o servidor de REDIRECIONAMENTO (HTTP -> HTTPS)
|
|
475
|
-
const httpRedirectPort =
|
|
481
|
+
const httpRedirectPort = exports.config.ssl.redirectPort;
|
|
476
482
|
http_1.default.createServer((req, res) => {
|
|
477
483
|
// Evita host header injection/open redirect: prefere hostname configurado
|
|
478
484
|
const rawHost = String(req.headers['host'] || '').trim();
|
|
@@ -503,12 +509,18 @@ async function initNativeServer(vattsApp, options, port, hostname) {
|
|
|
503
509
|
}
|
|
504
510
|
// Configurações de segurança do servidor (usa configuração personalizada)
|
|
505
511
|
server.setTimeout(vattsConfig.serverTimeout || 35000); // Timeout geral do servidor
|
|
506
|
-
|
|
507
|
-
server.
|
|
508
|
-
|
|
512
|
+
// @ts-ignore (Propriedades específicas do HTTP/1, HTTP/2 gerencia isso de forma diferente, mas mantemos para o server HTTP padrão)
|
|
513
|
+
if (server.maxHeadersCount)
|
|
514
|
+
server.maxHeadersCount = vattsConfig.maxHeadersCount || 100;
|
|
515
|
+
// @ts-ignore
|
|
516
|
+
if (server.headersTimeout)
|
|
517
|
+
server.headersTimeout = vattsConfig.headersTimeout || 60000;
|
|
518
|
+
// @ts-ignore
|
|
519
|
+
if (server.requestTimeout)
|
|
520
|
+
server.requestTimeout = vattsConfig.requestTimeout || 30000;
|
|
509
521
|
server.listen(port, hostname, () => {
|
|
510
|
-
sendBox({ ...options
|
|
511
|
-
msg.end(`${console_1.Colors.Bright}Ready on port ${console_1.Colors.BgGreen} ${
|
|
522
|
+
sendBox({ ...options });
|
|
523
|
+
msg.end(`${console_1.Colors.Bright}Ready on port ${console_1.Colors.BgGreen} ${exports.config?.port} ${console_1.Colors.Reset}${console_1.Colors.Bright} in ${Date.now() - time}ms${console_1.Colors.Reset}\n`);
|
|
512
524
|
});
|
|
513
525
|
// Configura WebSocket para hot reload (Comum a ambos)
|
|
514
526
|
vattsApp.setupWebSocket(server);
|
|
@@ -574,7 +586,7 @@ function app(options = {}) {
|
|
|
574
586
|
return serverApp;
|
|
575
587
|
},
|
|
576
588
|
/**
|
|
577
|
-
|
|
589
|
+
* Inicia um servidor Vatts.js fechado (o usuário não tem acesso ao framework)
|
|
578
590
|
*/
|
|
579
591
|
init: async () => {
|
|
580
592
|
const currentVersion = require('../package.json').version;
|
|
@@ -606,7 +618,7 @@ ${console_1.Colors.Bright + console_1.Colors.FgCyan} \\ / /\\ | | /__\
|
|
|
606
618
|
${console_1.Colors.Bright + console_1.Colors.FgCyan} \\/ /~~\\ | | .__/ .${console_1.Colors.FgWhite} \\__/ .__/ ${message}
|
|
607
619
|
|
|
608
620
|
`);
|
|
609
|
-
const actualPort =
|
|
621
|
+
const actualPort = exports.config?.port || 3000;
|
|
610
622
|
const actualHostname = options.hostname || "0.0.0.0";
|
|
611
623
|
if (framework !== 'native') {
|
|
612
624
|
console_1.default.warn(`The "${framework}" framework was selected, but the init() method only works with the "native" framework. Starting native server...`);
|
package/dist/index.js
CHANGED
|
@@ -347,7 +347,7 @@ import '${relativeEntryPath}';
|
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
function vatts(options) {
|
|
350
|
-
const { dev = true, dir = process.cwd(),
|
|
350
|
+
const { dev = true, dir = process.cwd(), envFiles } = options;
|
|
351
351
|
(0, env_1.loadEnv)({ dir, dev, envFiles });
|
|
352
352
|
// @ts-ignore
|
|
353
353
|
process.vatts = options;
|
|
@@ -482,7 +482,7 @@ function vatts(options) {
|
|
|
482
482
|
genericReq.hotReloadManager = hotReloadManager;
|
|
483
483
|
const { hostname } = req.headers;
|
|
484
484
|
const method = (genericReq.method || 'GET').toUpperCase();
|
|
485
|
-
const urlObj = new URL(genericReq.url, `http://${hostname}:${port}`);
|
|
485
|
+
const urlObj = new URL(genericReq.url, `http://${hostname}:${helpers_1.config?.port}`);
|
|
486
486
|
const pathname = urlObj.pathname;
|
|
487
487
|
if (pathname === types_1.RPC_ENDPOINT && method === 'POST') {
|
|
488
488
|
try {
|
package/dist/types.d.ts
CHANGED
|
@@ -16,15 +16,8 @@ export interface WebSocketContext {
|
|
|
16
16
|
export interface VattsOptions {
|
|
17
17
|
dev?: boolean;
|
|
18
18
|
hostname?: string;
|
|
19
|
-
port?: number;
|
|
20
19
|
dir?: string;
|
|
21
20
|
framework?: 'express' | 'fastify' | 'native';
|
|
22
|
-
ssl?: {
|
|
23
|
-
redirectPort: number;
|
|
24
|
-
key: string;
|
|
25
|
-
cert: string;
|
|
26
|
-
ca?: string;
|
|
27
|
-
};
|
|
28
21
|
envFiles?: string[];
|
|
29
22
|
}
|
|
30
23
|
/**
|
|
@@ -32,6 +25,13 @@ export interface VattsOptions {
|
|
|
32
25
|
* Essas configurações podem ser definidas no arquivo vatts.config.js
|
|
33
26
|
*/
|
|
34
27
|
export interface VattsConfig {
|
|
28
|
+
port: number;
|
|
29
|
+
ssl?: {
|
|
30
|
+
redirectPort: number;
|
|
31
|
+
key: string;
|
|
32
|
+
cert: string;
|
|
33
|
+
ca?: string;
|
|
34
|
+
};
|
|
35
35
|
/**
|
|
36
36
|
* Prefere utilizar rotas por path, sem precisar registrar?
|
|
37
37
|
* Padrão: false
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vatts",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1-alpha.1",
|
|
4
4
|
"description": "Vatts.js is a high-level framework for building web applications with ease and speed. It provides a robust set of tools and features to streamline development and enhance productivity.",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": "mfraz",
|