@purecore/one-server-4-all 0.1.0 → 0.3.0
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/CHANGELOG.md +16 -0
- package/COMPARACAO_LIVE_SERVER.md +37 -35
- package/README.md +44 -26
- package/hot-server.deps.graflow +1 -1
- package/package.json +3 -2
- package/reports/21-12-2025_04-21.md +25 -4
- package/reports/31-12-2025_21-15.md +2 -2
- package/reports/31-12-2025_21-45.md +1 -1
- package/reports/31-12-2025_22-00.md +1 -1
- package/src/cert-generator.ts +196 -158
- package/src/deployer.ts +6 -7
- package/src/index.ts +1 -1
- package/src/server.ts +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
# Release v0.5.2
|
|
2
|
+
|
|
3
|
+
### What's Changed
|
|
4
|
+
|
|
5
|
+
- 🚑 Alterada porta padrão de `6000` para `8080` (fix ERR_UNSAFE_PORT em browsers)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Release v0.5.1
|
|
10
|
+
|
|
11
|
+
### What's Changed
|
|
12
|
+
|
|
13
|
+
- 🐛 Correção no comando PM2 gerado para usar `npx one-server-4-all` em vez de caminho local
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
1
17
|
# Release v0.5.0
|
|
2
18
|
|
|
3
19
|
### What's Changed
|
|
@@ -1,38 +1,40 @@
|
|
|
1
1
|
# Comparativo: Purecore Hot Server vs Live Server
|
|
2
2
|
|
|
3
|
-
Este documento analisa as diferenças técnicas e de funcionalidades entre a **Sua biblioteca (`purecore-
|
|
3
|
+
Este documento analisa as diferenças técnicas e de funcionalidades entre a **Sua biblioteca (`purecore-one-server-4-all`)** e a biblioteca padrão de mercado **[`live-server`](https://github.com/tapio/live-server)**.
|
|
4
4
|
|
|
5
5
|
## 📊 Visão Geral
|
|
6
6
|
|
|
7
|
-
| Feature
|
|
8
|
-
|
|
|
9
|
-
| **Dependências**
|
|
10
|
-
| **Linguagem**
|
|
11
|
-
| **Hot Reload**
|
|
12
|
-
| **Watch System**
|
|
13
|
-
| **SPA Support**
|
|
14
|
-
| **Directory Listing**
|
|
15
|
-
| **HTTPS/Proxy**
|
|
16
|
-
| **Middleware**
|
|
17
|
-
| **Extensão `.html` opcional**
|
|
18
|
-
| **Compatível com `npx`/`npm i -g`** | Sim
|
|
7
|
+
| Feature | `live-server` (Tapio) | `purecore-one-server-4-all` (Sua Lib) |
|
|
8
|
+
| :---------------------------------- | :-------------------------------------------------- | :---------------------------------------------------------------- |
|
|
9
|
+
| **Dependências** | Múltiplas (`send`, `fsevents`, `opn`, `connect`...) | **Zero (0)** (Apenas nativas do Node.js) |
|
|
10
|
+
| **Linguagem** | JavaScript | **TypeScript** |
|
|
11
|
+
| **Hot Reload** | Full Page + **CSS Injection** (sem refresh) | Full Page + **CSS Injection** (sem refresh) |
|
|
12
|
+
| **Watch System** | `chokidar` (geralmente) | `fs.watch` nativo (recursivo) |
|
|
13
|
+
| **SPA Support** | Sim (redireciona 404 para index.html) | Sim (flag `--spa=true`) |
|
|
14
|
+
| **Directory Listing** | Sim (mostra arquivos se não houver index) | Não (retorna erro/404) |
|
|
15
|
+
| **HTTPS/Proxy** | Sim | HTTPS: Sim (flag `--https=true`) / Proxy: Não |
|
|
16
|
+
| **Middleware** | Sim (baseado em Connect) | Não |
|
|
17
|
+
| **Extensão `.html` opcional** | Não (depende do arquivo/rota) | Sim (fallback para servir `.html` quando a URL vier sem extensão) |
|
|
18
|
+
| **Compatível com `npx`/`npm i -g`** | Sim | Sim (via build `dist/` e campo `bin` no `package.json`) |
|
|
19
19
|
|
|
20
20
|
---
|
|
21
21
|
|
|
22
22
|
## ✅ O que a sua lib tem de Diferencial (Vantagens)
|
|
23
23
|
|
|
24
24
|
1. **Zero Dependencies (Zero Dependências)**:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
|
|
26
|
+
- **Segurança/Auditabilidade**: Ao não usar dependências de terceiros, você elimina riscos de _supply chain attacks_ e bloatware.
|
|
27
|
+
- **Instalação Instantânea**: `npm install` roda em milissegundos.
|
|
28
|
+
- **Tamanho**: O projeto final é minúsculo comparado ao `live-server` e suas árvores de dependência.
|
|
28
29
|
|
|
29
30
|
2. **Base de Código Moderna (TypeScript + Node 20+)**:
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
- O código utiliza APIs modernas como `node:fs/promises`, `node:watch` (recursivo) e Typescript estrito.
|
|
33
|
+
- É muito mais fácil para um desenvolvedor TS ler, entender e modificar o seu código do que o código legado JS do `live-server`.
|
|
32
34
|
|
|
33
35
|
3. **Simplicidade Arquitetural**:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
- Sua implementação de SSE (Server-Sent Events) é direta e transparente (`/_hot_server_sse`), sem dependência de bibliotecas complexas de socket.
|
|
37
|
+
- Validação "Zod-like" interna (`validator.ts`) demonstra como fazer type-safety sem bibliotecas pesadas.
|
|
36
38
|
|
|
37
39
|
---
|
|
38
40
|
|
|
@@ -42,36 +44,36 @@ Para igualar a funcionalidade, você precisaria implementar:
|
|
|
42
44
|
|
|
43
45
|
### 1. Injeção de CSS (CSS Hot Loading)
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
- **O que é**: Quando um arquivo `.css` é salvo, o `live-server` atualiza apenas o estilo na página sem recarregar o navegador.
|
|
48
|
+
- **Seu estado atual**: Implementado via SSE + troca de `href` com timestamp.
|
|
49
|
+
- **Como implementar**: No script injetado, verificar se a mensagem do SSE é sobre um arquivo CSS e, nesse caso, buscar as tags `<link rel="stylesheet">` no DOM e forçar uma atualização do `href` (ex: `style.css?v=timestamp`) em vez de dar reload.
|
|
48
50
|
|
|
49
51
|
### 2. Suporte a SPA (Single Page Applications)
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
- **O que é**: Frameworks como React/Vue (via Router) precisam que qualquer rota desconhecida (ex: `/usuarios/1`) retorne o `index.html` para que o JS no front assuma o controle.
|
|
54
|
+
- **Seu estado atual**: Implementado via flag `--spa=true` (fallback para `index.html` quando o arquivo não existe).
|
|
53
55
|
|
|
54
56
|
### 3. Mime-Types Robustos
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
- **Seu estado atual**: Implementado com lista expandida de tipos (vídeos, fontes, manifestos, etc).
|
|
57
59
|
|
|
58
60
|
### 4. CORS
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
- **Seu estado atual**: Implementado com headers `Access-Control-Allow-*` nas respostas.
|
|
61
63
|
|
|
62
64
|
### 5. Directory e Range Requests
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
- **O que falta**:
|
|
67
|
+
- **Listagem de pasta**: O `live-server` gera uma interface HTML listando os arquivos se você abrir uma pasta. O seu tenta abrir `index.html` e falha se não existir.
|
|
68
|
+
- **Range Requests**: Para fazer streaming de vídeo/áudio e permitir "pular" (seek) o vídeo, o servidor precisa suportar headers `Range` e `Content-Range`. O seu `createReadStream.pipe(res)` serve o arquivo inteiro, o que quebra alguns players de vídeo.
|
|
67
69
|
|
|
68
70
|
---
|
|
69
71
|
|
|
70
72
|
## 🔒 HTTPS (nota prática no WSL)
|
|
71
73
|
|
|
72
|
-
O `purecore-
|
|
74
|
+
O `purecore-one-server-4-all` suporta HTTPS com certificados auto-assinados para desenvolvimento local.
|
|
73
75
|
|
|
74
|
-
|
|
76
|
+
- **Gerar/limpar/inspecionar certs**:
|
|
75
77
|
|
|
76
78
|
```bash
|
|
77
79
|
bun run certs:clean
|
|
@@ -79,7 +81,7 @@ bun run certs:generate
|
|
|
79
81
|
bun run certs:info
|
|
80
82
|
```
|
|
81
83
|
|
|
82
|
-
|
|
84
|
+
- **Iniciar em HTTPS**:
|
|
83
85
|
|
|
84
86
|
```bash
|
|
85
87
|
bun run dev:https
|
|
@@ -89,8 +91,8 @@ bun run src/index.ts --https=true
|
|
|
89
91
|
|
|
90
92
|
**Referências**:
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
- Campo `bin` do npm (execução via `npx`/instalação global): `https://docs.npmjs.com/cli/v10/configuring-npm/package-json#bin`
|
|
95
|
+
- Node.js ESM/CJS (impacta como o `dist/` roda no Node): `https://nodejs.org/api/packages.html`
|
|
94
96
|
|
|
95
97
|
---
|
|
96
98
|
|
package/README.md
CHANGED
|
@@ -16,9 +16,9 @@ Um servidor de desenvolvimento hot-reload moderno e leve, construído com TypeSc
|
|
|
16
16
|
## 🚀 Instalação
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
npm install -g
|
|
19
|
+
npm install -g one-server-4-all
|
|
20
20
|
# ou
|
|
21
|
-
bun install -g
|
|
21
|
+
bun install -g one-server-4-all
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
## 🔒 Modo HTTPS
|
|
@@ -26,9 +26,10 @@ bun install -g hot-server
|
|
|
26
26
|
O Hot Server suporta HTTPS com certificados auto-assinados para desenvolvimento local.
|
|
27
27
|
|
|
28
28
|
### Ativar HTTPS
|
|
29
|
+
|
|
29
30
|
```bash
|
|
30
31
|
# Via linha de comando
|
|
31
|
-
|
|
32
|
+
one-server-4-all --https=true
|
|
32
33
|
|
|
33
34
|
# Via npm scripts
|
|
34
35
|
npm run dev:https
|
|
@@ -38,6 +39,7 @@ bun run dev:https
|
|
|
38
39
|
```
|
|
39
40
|
|
|
40
41
|
### Gerenciamento de Certificados
|
|
42
|
+
|
|
41
43
|
```bash
|
|
42
44
|
# Gerar certificados auto-assinados
|
|
43
45
|
npm run certs:generate
|
|
@@ -49,30 +51,34 @@ npm run certs:info
|
|
|
49
51
|
npm run certs:clean
|
|
50
52
|
```
|
|
51
53
|
|
|
52
|
-
**Nota**: Os certificados são salvos em `.
|
|
54
|
+
**Nota**: Os certificados são salvos em `.one-server-4-all-certs/` no diretório do projeto.
|
|
53
55
|
|
|
54
56
|
## 📖 Uso Básico
|
|
55
57
|
|
|
56
58
|
```bash
|
|
57
59
|
# Na pasta do seu projeto
|
|
58
|
-
|
|
60
|
+
one-server-4-all
|
|
59
61
|
|
|
60
62
|
# Com opções
|
|
61
|
-
|
|
63
|
+
one-server-4-all --port=3000 --spa=true
|
|
62
64
|
```
|
|
63
65
|
|
|
64
66
|
## 🎯 Funcionalidades Avançadas
|
|
65
67
|
|
|
66
68
|
### CSS Hot Loading
|
|
69
|
+
|
|
67
70
|
Quando você modifica arquivos `.css`, apenas o estilo é atualizado sem recarregar a página inteira.
|
|
68
71
|
|
|
69
72
|
### SPA Support
|
|
73
|
+
|
|
70
74
|
```bash
|
|
71
|
-
|
|
75
|
+
one-server-4-all --spa=true
|
|
72
76
|
```
|
|
77
|
+
|
|
73
78
|
Rotas inexistentes (como `/usuarios/1`) automaticamente servem `index.html`, permitindo que seu framework frontend assuma o roteamento.
|
|
74
79
|
|
|
75
80
|
### MIME Types Suportados
|
|
81
|
+
|
|
76
82
|
- **Vídeos**: MP4, WebM, OGG, AVI, MOV, WMV, FLV
|
|
77
83
|
- **Áudios**: MP3, WAV, OGG, AAC, M4A, Opus
|
|
78
84
|
- **Fontes**: WOFF, WOFF2, TTF, OTF, EOT
|
|
@@ -82,19 +88,20 @@ Rotas inexistentes (como `/usuarios/1`) automaticamente servem `index.html`, per
|
|
|
82
88
|
|
|
83
89
|
## 🔧 Opções de CLI
|
|
84
90
|
|
|
85
|
-
| Opção
|
|
86
|
-
|
|
87
|
-
| `--port=<number>`
|
|
88
|
-
| `--root=<path>`
|
|
89
|
-
| `--open=<true/false>`
|
|
90
|
-
| `--spa=<true/false>`
|
|
91
|
-
| `--https=<true/false>` | Habilitar modo HTTPS
|
|
91
|
+
| Opção | Descrição | Padrão |
|
|
92
|
+
| ---------------------- | ------------------------------- | --------------------- |
|
|
93
|
+
| `--port=<number>` | Porta do servidor | `9999` |
|
|
94
|
+
| `--root=<path>` | Diretório raiz | `.` (diretório atual) |
|
|
95
|
+
| `--open=<true/false>` | Abrir navegador automaticamente | `true` |
|
|
96
|
+
| `--spa=<true/false>` | Habilitar suporte SPA | `false` |
|
|
97
|
+
| `--https=<true/false>` | Habilitar modo HTTPS | `false` |
|
|
92
98
|
|
|
93
99
|
## 🏗️ Como foi feito
|
|
94
100
|
|
|
95
101
|
Este projeto foi desenvolvido seguindo uma arquitetura minimalista e moderna:
|
|
96
102
|
|
|
97
103
|
### Técnicas Utilizadas
|
|
104
|
+
|
|
98
105
|
1. **TypeScript Estrito**: Tipagem forte em todo o código
|
|
99
106
|
2. **APIs Nativas**: Uso exclusivo de módulos `node:*`
|
|
100
107
|
3. **Server-Sent Events**: Comunicação bidirecional eficiente
|
|
@@ -103,6 +110,7 @@ Este projeto foi desenvolvido seguindo uma arquitetura minimalista e moderna:
|
|
|
103
110
|
6. **CSS Injection**: DOM manipulation para hot reload inteligente
|
|
104
111
|
|
|
105
112
|
### Arquitetura
|
|
113
|
+
|
|
106
114
|
```
|
|
107
115
|
src/
|
|
108
116
|
├── index.ts # CLI e configuração
|
|
@@ -112,6 +120,7 @@ src/
|
|
|
112
120
|
```
|
|
113
121
|
|
|
114
122
|
### Funcionamento
|
|
123
|
+
|
|
115
124
|
1. **Watcher** monitora mudanças recursivamente usando `fs.watch`
|
|
116
125
|
2. **Server** serve arquivos estáticos com MIME types corretos
|
|
117
126
|
3. **SSE** notifica clientes sobre mudanças em tempo real
|
|
@@ -121,30 +130,36 @@ src/
|
|
|
121
130
|
## 🧪 Como testar
|
|
122
131
|
|
|
123
132
|
### Teste CSS Injection
|
|
124
|
-
|
|
133
|
+
|
|
134
|
+
1. Inicie o servidor: `one-server-4-all`
|
|
125
135
|
2. Modifique qualquer arquivo `.css`
|
|
126
136
|
3. Observe que apenas o CSS é atualizado, sem reload da página
|
|
127
137
|
|
|
128
138
|
### Teste SPA Support
|
|
129
|
-
|
|
139
|
+
|
|
140
|
+
1. Inicie com SPA: `one-server-4-all --spa=true`
|
|
130
141
|
2. Acesse `/qualquer-rota-inexistente`
|
|
131
142
|
3. Deve carregar `index.html` em vez de 404
|
|
132
143
|
|
|
133
144
|
### Teste MIME Types
|
|
145
|
+
|
|
134
146
|
1. Adicione arquivos de vídeo/fonte no seu projeto
|
|
135
147
|
2. Eles serão servidos com headers corretos
|
|
136
148
|
|
|
137
149
|
### Teste CORS
|
|
150
|
+
|
|
138
151
|
1. Acesse arquivos de outro domínio/origin
|
|
139
152
|
2. Deve funcionar sem erros de CORS
|
|
140
153
|
|
|
141
154
|
### Teste HTTPS
|
|
142
|
-
|
|
155
|
+
|
|
156
|
+
1. Execute: `one-server-4-all --https=true`
|
|
143
157
|
2. Observe o emoji 🔒 no log do terminal
|
|
144
158
|
3. Acesse https://localhost:9999
|
|
145
159
|
4. Aceite o aviso de certificado auto-assinado
|
|
146
160
|
|
|
147
161
|
### Teste Logs Detalhados
|
|
162
|
+
|
|
148
163
|
1. Abra uma página HTML
|
|
149
164
|
2. Observe no terminal:
|
|
150
165
|
- 📄 Arquivos servidos com tamanho e tipo MIME
|
|
@@ -154,20 +169,21 @@ src/
|
|
|
154
169
|
## 📊 Comparação com Live Server
|
|
155
170
|
|
|
156
171
|
| Feature | Live Server | Purecore Hot Server |
|
|
157
|
-
|
|
158
|
-
| **Dependencies** | Múltiplas | ❌ Zero
|
|
159
|
-
| **Language** | JavaScript | ✅ TypeScript
|
|
160
|
-
| **CSS Injection** | ✅ Sim
|
|
161
|
-
| **SPA Support** | ✅ Sim
|
|
162
|
-
| **MIME Types** | Básicos | ✅ Robustos
|
|
163
|
-
| **CORS** | ❌ Não
|
|
164
|
-
| **Installation** | Lento | ✅ Instantâneo
|
|
172
|
+
| ----------------- | ----------- | ------------------- |
|
|
173
|
+
| **Dependencies** | Múltiplas | ❌ Zero |
|
|
174
|
+
| **Language** | JavaScript | ✅ TypeScript |
|
|
175
|
+
| **CSS Injection** | ✅ Sim | ✅ Sim |
|
|
176
|
+
| **SPA Support** | ✅ Sim | ✅ Sim |
|
|
177
|
+
| **MIME Types** | Básicos | ✅ Robustos |
|
|
178
|
+
| **CORS** | ❌ Não | ✅ Sim |
|
|
179
|
+
| **Installation** | Lento | ✅ Instantâneo |
|
|
165
180
|
|
|
166
181
|
## 🔍 Análise de Dependências Obsoletas
|
|
167
182
|
|
|
168
183
|
Durante o desenvolvimento, analisamos dependências comuns em servidores de desenvolvimento e identificamos quais são desnecessárias no Node.js moderno:
|
|
169
184
|
|
|
170
185
|
### ❌ Dependências Obsoletas
|
|
186
|
+
|
|
171
187
|
- **`object-assign`**: Substituído por `Object.assign()` nativo
|
|
172
188
|
- **`http-auth`**: Autenticação HTTP pode ser feita nativamente
|
|
173
189
|
- **`colors`**: Node.js 20+ tem `util.styleText()` nativo
|
|
@@ -175,6 +191,7 @@ Durante o desenvolvimento, analisamos dependências comuns em servidores de dese
|
|
|
175
191
|
- **`event-stream`**: ⚠️ Vulnerabilidade conhecida, usar streams nativos
|
|
176
192
|
|
|
177
193
|
### ⚡ Alternativas Nativas Utilizadas
|
|
194
|
+
|
|
178
195
|
- **File System**: `node:fs` com `fs.watch()` recursivo
|
|
179
196
|
- **HTTP Server**: `node:http` e `node:https` nativos
|
|
180
197
|
- **Crypto**: `node:crypto` para certificados HTTPS
|
|
@@ -182,6 +199,7 @@ Durante o desenvolvimento, analisamos dependências comuns em servidores de dese
|
|
|
182
199
|
- **Streams**: `node:stream` para Server-Sent Events
|
|
183
200
|
|
|
184
201
|
### 🎯 Resultado
|
|
202
|
+
|
|
185
203
|
**Zero dependências externas** = instalação instantânea, sem vulnerabilidades de terceiros, e compatibilidade garantida com futuras versões do Node.js.
|
|
186
204
|
|
|
187
205
|
## 📝 Changelog
|
|
@@ -194,4 +212,4 @@ Contribuições são bem-vindas! Este projeto segue uma filosofia de **zero depe
|
|
|
194
212
|
|
|
195
213
|
## 📄 Licença
|
|
196
214
|
|
|
197
|
-
MIT
|
|
215
|
+
MIT
|
package/hot-server.deps.graflow
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(
|
|
1
|
+
(one-server-4-all)->(0.1.0)
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purecore/one-server-4-all",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Zero dependency modern hot-reload server replacement",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
8
|
"one-server": "./dist/index.js",
|
|
9
|
+
"one-server-4-all": "./dist/index.js",
|
|
9
10
|
"vai-server": "./dist/index.js"
|
|
10
11
|
},
|
|
11
12
|
"scripts": {
|
|
@@ -21,7 +22,7 @@
|
|
|
21
22
|
"keywords": [
|
|
22
23
|
"http-server",
|
|
23
24
|
"hot-reload",
|
|
24
|
-
"
|
|
25
|
+
"one-server-4-all",
|
|
25
26
|
"live-server",
|
|
26
27
|
"zero-dependency"
|
|
27
28
|
],
|
|
@@ -9,17 +9,20 @@ Foram implementadas com sucesso as funcionalidades de HTTPS, geração automáti
|
|
|
9
9
|
### 1. 🔒 Suporte Completo a HTTPS
|
|
10
10
|
|
|
11
11
|
**O que foi implementado:**
|
|
12
|
+
|
|
12
13
|
- Modo HTTPS opcional ativado pela flag `--https=true`
|
|
13
14
|
- Geração automática de certificados SSL auto-assinados
|
|
14
15
|
- Servidor HTTP/HTTPS dinâmico baseado na configuração
|
|
15
16
|
- Suporte completo a protocolos HTTP e HTTPS
|
|
16
17
|
|
|
17
18
|
**Arquivos modificados:**
|
|
19
|
+
|
|
18
20
|
- `src/server.ts`: Classe HotServer modificada para suportar HTTPS
|
|
19
21
|
- `src/index.ts`: Parsing da flag `--https`
|
|
20
22
|
- `src/validator.ts`: Validação da configuração HTTPS
|
|
21
23
|
|
|
22
24
|
**Técnicas utilizadas:**
|
|
25
|
+
|
|
23
26
|
- Módulo `https` do Node.js para servidor SSL
|
|
24
27
|
- Detecção automática de certificados existentes
|
|
25
28
|
- Fallback gracioso para modo HTTP quando necessário
|
|
@@ -28,15 +31,18 @@ Foram implementadas com sucesso as funcionalidades de HTTPS, geração automáti
|
|
|
28
31
|
### 2. 🛠️ Sistema de Geração de Certificados
|
|
29
32
|
|
|
30
33
|
**O que foi implementado:**
|
|
34
|
+
|
|
31
35
|
- Classe `CertGenerator` completa para gerenciamento de certificados
|
|
32
36
|
- Geração automática de pares chave privada/certificado
|
|
33
37
|
- Comandos CLI para geração, limpeza e informações
|
|
34
|
-
- Certificados salvos em `.
|
|
38
|
+
- Certificados salvos em `.one-server-4-all-certs/` padrão
|
|
35
39
|
|
|
36
40
|
**Arquivos criados:**
|
|
41
|
+
|
|
37
42
|
- `src/cert-generator.ts`: Sistema completo de geração de certificados
|
|
38
43
|
|
|
39
44
|
**Técnicas utilizadas:**
|
|
45
|
+
|
|
40
46
|
- Crypto API nativa do Node.js para geração RSA
|
|
41
47
|
- File system operations para persistência
|
|
42
48
|
- Command-line interface com subcomandos
|
|
@@ -45,6 +51,7 @@ Foram implementadas com sucesso as funcionalidades de HTTPS, geração automáti
|
|
|
45
51
|
### 3. 🔓🔒 Indicadores Visuais no Terminal
|
|
46
52
|
|
|
47
53
|
**O que foi implementado:**
|
|
54
|
+
|
|
48
55
|
- Emojis de cadeado no log de inicialização:
|
|
49
56
|
- 🔓 para modo HTTP (cadeado aberto)
|
|
50
57
|
- 🔒 para modo HTTPS (cadeado fechado)
|
|
@@ -52,9 +59,11 @@ Foram implementadas com sucesso as funcionalidades de HTTPS, geração automáti
|
|
|
52
59
|
- Visual feedback imediato do modo de segurança
|
|
53
60
|
|
|
54
61
|
**Arquivos modificados:**
|
|
62
|
+
|
|
55
63
|
- `src/server.ts`: Logs de inicialização com indicadores visuais
|
|
56
64
|
|
|
57
65
|
**Técnicas utilizadas:**
|
|
66
|
+
|
|
58
67
|
- Template literals com emojis Unicode
|
|
59
68
|
- Detecção dinâmica de protocolo
|
|
60
69
|
- Console output formatting
|
|
@@ -62,6 +71,7 @@ Foram implementadas com sucesso as funcionalidades de HTTPS, geração automáti
|
|
|
62
71
|
### 4. 📊 Sistema Avançado de Logs
|
|
63
72
|
|
|
64
73
|
**O que foi implementado:**
|
|
74
|
+
|
|
65
75
|
- Logs detalhados para cada arquivo servido
|
|
66
76
|
- Informações de tamanho e tipo MIME
|
|
67
77
|
- Parsing automático de recursos HTML
|
|
@@ -69,9 +79,11 @@ Foram implementadas com sucesso as funcionalidades de HTTPS, geração automáti
|
|
|
69
79
|
- Logs especiais para injeção de hot-reload
|
|
70
80
|
|
|
71
81
|
**Arquivos modificados:**
|
|
82
|
+
|
|
72
83
|
- `src/server.ts`: Sistema completo de logging
|
|
73
84
|
|
|
74
85
|
**Técnicas utilizadas:**
|
|
86
|
+
|
|
75
87
|
- Regex parsing para recursos HTML
|
|
76
88
|
- File system stats para informações de tamanho
|
|
77
89
|
- Formatação human-readable de bytes
|
|
@@ -80,6 +92,7 @@ Foram implementadas com sucesso as funcionalidades de HTTPS, geração automáti
|
|
|
80
92
|
## 🔧 Funcionalidades Técnicas
|
|
81
93
|
|
|
82
94
|
### Scripts NPM Adicionados
|
|
95
|
+
|
|
83
96
|
```json
|
|
84
97
|
{
|
|
85
98
|
"dev:https": "ts-node src/index.ts --https=true",
|
|
@@ -90,18 +103,20 @@ Foram implementadas com sucesso as funcionalidades de HTTPS, geração automáti
|
|
|
90
103
|
```
|
|
91
104
|
|
|
92
105
|
### Estrutura de Certificados
|
|
106
|
+
|
|
93
107
|
```
|
|
94
|
-
.
|
|
108
|
+
.one-server-4-all-certs/
|
|
95
109
|
├── localhost.key # Chave privada RSA
|
|
96
110
|
└── localhost.crt # Certificado auto-assinado
|
|
97
111
|
```
|
|
98
112
|
|
|
99
113
|
### Exemplo de Logs de Saída
|
|
114
|
+
|
|
100
115
|
```
|
|
101
116
|
🔐 Gerando certificados auto-assinados...
|
|
102
117
|
✅ Certificados gerados com sucesso!
|
|
103
118
|
|
|
104
|
-
🚀
|
|
119
|
+
🚀 one-server-4-all rodando!
|
|
105
120
|
-----------------------------------
|
|
106
121
|
📂 Root: /path/to/project
|
|
107
122
|
🔒 Local: https://localhost:9999
|
|
@@ -118,6 +133,7 @@ Foram implementadas com sucesso as funcionalidades de HTTPS, geração automáti
|
|
|
118
133
|
## 🧪 Como Testar
|
|
119
134
|
|
|
120
135
|
### Modo HTTPS
|
|
136
|
+
|
|
121
137
|
```bash
|
|
122
138
|
# Ativar HTTPS
|
|
123
139
|
npm run dev:https
|
|
@@ -127,6 +143,7 @@ ts-node src/index.ts --https=true
|
|
|
127
143
|
```
|
|
128
144
|
|
|
129
145
|
### Gerenciamento de Certificados
|
|
146
|
+
|
|
130
147
|
```bash
|
|
131
148
|
# Gerar certificados
|
|
132
149
|
npm run certs:generate
|
|
@@ -139,6 +156,7 @@ npm run certs:clean
|
|
|
139
156
|
```
|
|
140
157
|
|
|
141
158
|
### Logs Detalhados
|
|
159
|
+
|
|
142
160
|
1. Inicie o servidor
|
|
143
161
|
2. Abra uma página HTML no navegador
|
|
144
162
|
3. Observe no terminal:
|
|
@@ -149,16 +167,19 @@ npm run certs:clean
|
|
|
149
167
|
## 📈 Benefícios Alcançados
|
|
150
168
|
|
|
151
169
|
### Segurança
|
|
170
|
+
|
|
152
171
|
- ✅ Desenvolvimento local com HTTPS
|
|
153
172
|
- ✅ Certificados auto-gerados automaticamente
|
|
154
173
|
- ✅ Feedback visual de segurança
|
|
155
174
|
|
|
156
175
|
### Desenvolvimento
|
|
176
|
+
|
|
157
177
|
- ✅ Logs detalhados para debugging
|
|
158
178
|
- ✅ Visibilidade de recursos HTML
|
|
159
179
|
- ✅ Protocol-aware operations
|
|
160
180
|
|
|
161
181
|
### Experiência do Desenvolvedor
|
|
182
|
+
|
|
162
183
|
- ✅ Indicadores visuais claros
|
|
163
184
|
- ✅ Automação de tarefas repetitivas
|
|
164
185
|
- ✅ CLI intuitiva e completa
|
|
@@ -181,4 +202,4 @@ O Purecore Hot Server agora oferece:
|
|
|
181
202
|
- [OpenSSL Certificate Generation](https://www.openssl.org/docs/man1.1.1/man1/req.html)
|
|
182
203
|
- [MDN Web Docs - SSL/TLS](https://developer.mozilla.org/en-US/docs/Glossary/SSL)
|
|
183
204
|
- [RFC 5280 - Certificate Standards](https://tools.ietf.org/html/rfc5280)
|
|
184
|
-
- [Unicode Emoji Reference](https://unicode.org/emoji/charts/full-emoji-list.html)
|
|
205
|
+
- [Unicode Emoji Reference](https://unicode.org/emoji/charts/full-emoji-list.html)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Relatório de Modificação - Log Estilo Vite
|
|
2
2
|
|
|
3
3
|
**Data:** 31-12-2025
|
|
4
|
-
**Tarefa:** Customizar o log de inicialização do `
|
|
4
|
+
**Tarefa:** Customizar o log de inicialização do `one-server-4-all` para ser idêntico ao do Vite.
|
|
5
5
|
|
|
6
6
|
## O que foi feito
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
- Implementada a detecção de interfaces de rede usando o módulo nativo `node:os`.
|
|
10
10
|
- Adicionada medição de tempo de inicialização (`startTime`) para exibir "ready in X ms".
|
|
11
11
|
- Estilização completa usando códigos de escape ANSI para cores e negrito, imitando perfeitamente o visual premium do Vite.
|
|
12
|
-
- Substituído o nome "VITE" por "
|
|
12
|
+
- Substituído o nome "VITE" por "one-server-4-all".
|
|
13
13
|
- Adicionado o link de ajuda "press h + enter to show help".
|
|
14
14
|
- Atualizado o feedback de porta em uso para também seguir o padrão visual.
|
|
15
15
|
- Corrigido o `.gitignore` para incluir a pasta `dist`.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Relatório de Modificação - Implementação do Deployer Interativo
|
|
2
2
|
|
|
3
3
|
**Data:** 31-12-2025
|
|
4
|
-
**Tarefa:** Substituir o script `cria.sh` por um comando `deploy` interativo integrado ao CLI do `
|
|
4
|
+
**Tarefa:** Substituir o script `cria.sh` por um comando `deploy` interativo integrado ao CLI do `one-server-4-all`.
|
|
5
5
|
|
|
6
6
|
## O que foi feito
|
|
7
7
|
|
package/src/cert-generator.ts
CHANGED
|
@@ -1,173 +1,211 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import crypto from
|
|
3
|
-
import fs from
|
|
4
|
-
import path from
|
|
5
|
-
import { execFileSync } from
|
|
2
|
+
import crypto from "node:crypto";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { execFileSync } from "node:child_process";
|
|
6
6
|
|
|
7
7
|
export class CertGenerator {
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
8
|
+
private static readonly CERT_DIR = ".one-server-4-all-certs";
|
|
9
|
+
private static readonly KEY_FILE = "localhost.key";
|
|
10
|
+
private static readonly CERT_FILE = "localhost.crt";
|
|
11
|
+
|
|
12
|
+
static async generateCerts() {
|
|
13
|
+
const certDir = path.join(process.cwd(), this.CERT_DIR);
|
|
14
|
+
const keyPath = path.join(certDir, this.KEY_FILE);
|
|
15
|
+
const certPath = path.join(certDir, this.CERT_FILE);
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// Verificar se certificados já existem
|
|
19
|
+
try {
|
|
20
|
+
await fs.access(keyPath);
|
|
21
|
+
await fs.access(certPath);
|
|
22
|
+
console.log("📋 Certificados já existem em:", certDir);
|
|
23
|
+
return { keyPath, certPath };
|
|
24
|
+
} catch {
|
|
25
|
+
// Certificados não existem, vamos criar
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Criar diretório se não existir
|
|
29
|
+
await fs.mkdir(certDir, { recursive: true });
|
|
30
|
+
|
|
31
|
+
console.log("🔐 Gerando certificados auto-assinados...");
|
|
32
|
+
|
|
33
|
+
// Observação importante:
|
|
34
|
+
// Gerar um X509 "de verdade" apenas com node:crypto (sem libs externas) não é trivial.
|
|
35
|
+
// Como este projeto roda no WSL, utilizamos o OpenSSL (toolchain padrão do Linux)
|
|
36
|
+
// para gerar um par key/cert PEM válido e compatível com Bun/BoringSSL.
|
|
37
|
+
await this.generateWithOpenSSL({ keyPath, certPath });
|
|
38
|
+
|
|
39
|
+
// Validação do PEM (evita subir servidor com arquivo corrompido)
|
|
40
|
+
const [keyPem, certPem] = await Promise.all([
|
|
41
|
+
fs.readFile(keyPath, "utf8"),
|
|
42
|
+
fs.readFile(certPath, "utf8"),
|
|
43
|
+
]);
|
|
44
|
+
this.validatePem({ keyPem, certPem, keyPath, certPath });
|
|
45
|
+
this.validateX509(certPem, certPath);
|
|
46
|
+
this.validateWithOpenSSL(certPath);
|
|
47
|
+
|
|
48
|
+
console.log("✅ Certificados gerados com sucesso!");
|
|
49
|
+
console.log("📁 Localização:", certDir);
|
|
50
|
+
console.log("🔑 Chave privada:", keyPath);
|
|
51
|
+
console.log("📄 Certificado:", certPath);
|
|
52
|
+
console.log("");
|
|
53
|
+
console.log(
|
|
54
|
+
"⚠️ AVISO: Estes são certificados auto-assinados para desenvolvimento local."
|
|
55
|
+
);
|
|
56
|
+
console.log(" Não use em produção!");
|
|
57
|
+
|
|
58
|
+
return { keyPath, certPath };
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error("❌ Erro ao gerar certificados:", error);
|
|
61
|
+
throw error;
|
|
62
62
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private static generateWithOpenSSL(params: {
|
|
66
|
+
keyPath: string;
|
|
67
|
+
certPath: string;
|
|
68
|
+
}) {
|
|
69
|
+
const { keyPath, certPath } = params;
|
|
70
|
+
const subj = "/C=BR/ST=SP/L=Sao Paulo/O=Purecore/OU=Dev/CN=localhost";
|
|
71
|
+
|
|
72
|
+
// Preferimos SAN para evitar problemas em clients modernos.
|
|
73
|
+
// Nem todo OpenSSL antigo suporta -addext, então fazemos fallback.
|
|
74
|
+
const baseArgs = [
|
|
75
|
+
"req",
|
|
76
|
+
"-x509",
|
|
77
|
+
"-newkey",
|
|
78
|
+
"rsa:2048",
|
|
79
|
+
"-keyout",
|
|
80
|
+
keyPath,
|
|
81
|
+
"-out",
|
|
82
|
+
certPath,
|
|
83
|
+
"-days",
|
|
84
|
+
"365",
|
|
85
|
+
"-nodes",
|
|
86
|
+
"-subj",
|
|
87
|
+
subj,
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
execFileSync(
|
|
92
|
+
"openssl",
|
|
93
|
+
[...baseArgs, "-addext", "subjectAltName=DNS:localhost,IP:127.0.0.1"],
|
|
94
|
+
{ stdio: "inherit" }
|
|
95
|
+
);
|
|
96
|
+
} catch {
|
|
97
|
+
execFileSync("openssl", baseArgs, { stdio: "inherit" });
|
|
77
98
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private static validatePem(params: {
|
|
102
|
+
keyPem: string;
|
|
103
|
+
certPem: string;
|
|
104
|
+
keyPath: string;
|
|
105
|
+
certPath: string;
|
|
106
|
+
}) {
|
|
107
|
+
const { keyPem, certPem, keyPath, certPath } = params;
|
|
108
|
+
const keyOk =
|
|
109
|
+
keyPem.includes("-----BEGIN PRIVATE KEY-----") ||
|
|
110
|
+
keyPem.includes("-----BEGIN RSA PRIVATE KEY-----");
|
|
111
|
+
const certOk = certPem.includes("-----BEGIN CERTIFICATE-----");
|
|
112
|
+
|
|
113
|
+
if (!keyOk || !certOk) {
|
|
114
|
+
throw new Error(
|
|
115
|
+
`PEM inválido gerado. ` +
|
|
116
|
+
`keyOk=${keyOk} certOk=${certOk}. ` +
|
|
117
|
+
`keyPath=${keyPath} certPath=${certPath}`
|
|
118
|
+
);
|
|
93
119
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
private static validateX509(certPem: string, certPath: string) {
|
|
123
|
+
try {
|
|
124
|
+
// Node valida a estrutura do X509 e falha se base64/DER estiverem inválidos.
|
|
125
|
+
// Isso é um bom "gate" antes de subir o https.createServer().
|
|
126
|
+
// @ts-ignore - Bun/Node expõem X509Certificate em node:crypto
|
|
127
|
+
const x509 = new crypto.X509Certificate(certPem);
|
|
128
|
+
if (!x509.subject) {
|
|
129
|
+
throw new Error("X509 sem subject");
|
|
130
|
+
}
|
|
131
|
+
} catch (error: any) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
`Certificado X509 inválido em ${certPath}: ${
|
|
134
|
+
error?.message || String(error)
|
|
135
|
+
}`
|
|
136
|
+
);
|
|
107
137
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private static validateWithOpenSSL(certPath: string) {
|
|
141
|
+
try {
|
|
142
|
+
// OpenSSL é a validação "ground truth" no WSL.
|
|
143
|
+
execFileSync("openssl", ["x509", "-in", certPath, "-noout"], {
|
|
144
|
+
stdio: "ignore",
|
|
145
|
+
});
|
|
146
|
+
} catch (error: any) {
|
|
147
|
+
throw new Error(`OpenSSL não conseguiu ler o certificado (${certPath}).`);
|
|
116
148
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static async getCertPaths(): Promise<{
|
|
152
|
+
keyPath: string;
|
|
153
|
+
certPath: string;
|
|
154
|
+
} | null> {
|
|
155
|
+
const certDir = path.join(process.cwd(), this.CERT_DIR);
|
|
156
|
+
const keyPath = path.join(certDir, this.KEY_FILE);
|
|
157
|
+
const certPath = path.join(certDir, this.CERT_FILE);
|
|
158
|
+
|
|
159
|
+
try {
|
|
160
|
+
await fs.access(keyPath);
|
|
161
|
+
await fs.access(certPath);
|
|
162
|
+
return { keyPath, certPath };
|
|
163
|
+
} catch {
|
|
164
|
+
return null;
|
|
130
165
|
}
|
|
166
|
+
}
|
|
131
167
|
|
|
132
|
-
|
|
133
|
-
|
|
168
|
+
static async cleanCerts() {
|
|
169
|
+
const certDir = path.join(process.cwd(), this.CERT_DIR);
|
|
134
170
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
171
|
+
try {
|
|
172
|
+
await fs.rm(certDir, { recursive: true, force: true });
|
|
173
|
+
console.log("🗑️ Certificados removidos:", certDir);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
console.error("❌ Erro ao remover certificados:", error);
|
|
141
176
|
}
|
|
177
|
+
}
|
|
142
178
|
}
|
|
143
179
|
|
|
144
180
|
// Executar se chamado diretamente
|
|
145
|
-
if (typeof require !==
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
181
|
+
if (typeof require !== "undefined" && require.main === module) {
|
|
182
|
+
const command = process.argv[2];
|
|
183
|
+
|
|
184
|
+
switch (command) {
|
|
185
|
+
case "generate":
|
|
186
|
+
case undefined:
|
|
187
|
+
CertGenerator.generateCerts().catch(console.error);
|
|
188
|
+
break;
|
|
189
|
+
case "clean":
|
|
190
|
+
CertGenerator.cleanCerts().catch(console.error);
|
|
191
|
+
break;
|
|
192
|
+
case "info":
|
|
193
|
+
CertGenerator.getCertPaths()
|
|
194
|
+
.then((paths) => {
|
|
195
|
+
if (paths) {
|
|
196
|
+
console.log("📋 Certificados encontrados:");
|
|
197
|
+
console.log("🔑 Chave:", paths.keyPath);
|
|
198
|
+
console.log("📄 Certificado:", paths.certPath);
|
|
199
|
+
} else {
|
|
200
|
+
console.log("❌ Nenhum certificado encontrado");
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
.catch(console.error);
|
|
204
|
+
break;
|
|
205
|
+
default:
|
|
206
|
+
console.log("Uso: cert-generator [generate|clean|info]");
|
|
207
|
+
console.log(" generate: Gera certificados auto-assinados (padrão)");
|
|
208
|
+
console.log(" clean: Remove certificados existentes");
|
|
209
|
+
console.log(" info: Mostra informações dos certificados");
|
|
210
|
+
}
|
|
211
|
+
}
|
package/src/deployer.ts
CHANGED
|
@@ -22,7 +22,7 @@ export class Deployer {
|
|
|
22
22
|
|
|
23
23
|
private printBanner() {
|
|
24
24
|
console.log(
|
|
25
|
-
`\n ${bold(magenta("🚀
|
|
25
|
+
`\n ${bold(magenta("🚀 one-server-4-all DEPLOYER"))} ${gray("v0.4.0")}`
|
|
26
26
|
);
|
|
27
27
|
console.log(` ${gray("─────────────────────────────────────────")}\n`);
|
|
28
28
|
}
|
|
@@ -45,9 +45,9 @@ export class Deployer {
|
|
|
45
45
|
const port =
|
|
46
46
|
(await this.question(
|
|
47
47
|
` ${cyan("➜")} ${bold("Qual a porta do servidor?")} ${gray(
|
|
48
|
-
"(padrão
|
|
48
|
+
"(padrão 8080)"
|
|
49
49
|
)}\n ${green("❯")} `
|
|
50
|
-
)) || "
|
|
50
|
+
)) || "8080";
|
|
51
51
|
|
|
52
52
|
const confirmNginx = await this.question(
|
|
53
53
|
` ${cyan("➜")} ${bold(
|
|
@@ -69,11 +69,10 @@ export class Deployer {
|
|
|
69
69
|
const name = domain.split(".")[0];
|
|
70
70
|
|
|
71
71
|
// Monta o comando PM2
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
// Vamos gerar o comando COM os certificados se eles existirem, e setar https=true
|
|
72
|
+
// Usamos npx para garantir que rode o pacote instalado ou baixe se necessário
|
|
73
|
+
// A sintaxe para PM2 rodar executáveis arbitrários requer 'pm2 start "cmd" --name ...' ou usar o interpreter
|
|
75
74
|
|
|
76
|
-
let pm2Command = `pm2 start
|
|
75
|
+
let pm2Command = `pm2 start "npx one-server-4-all" --name "${domain}" -- --port=${port} --open=false`;
|
|
77
76
|
|
|
78
77
|
if (certPaths.key && certPaths.cert) {
|
|
79
78
|
// Nota: Node node pode não ter permissão de ler /etc/letsencrypt diretamente dependendo do user
|
package/src/index.ts
CHANGED
|
@@ -24,7 +24,7 @@ if (args[0] === "deploy") {
|
|
|
24
24
|
const rootArg = args[0] && !args[0].startsWith("--") ? args[0] : ".";
|
|
25
25
|
|
|
26
26
|
const rawConfig = {
|
|
27
|
-
port: parseInt(getArg("port", "
|
|
27
|
+
port: parseInt(getArg("port", "8080")),
|
|
28
28
|
root: path.resolve(process.cwd(), rootArg),
|
|
29
29
|
open: getArg("open", "true"), // 'true' por padrão
|
|
30
30
|
spa: getArg("spa", "false"), // 'false' por padrão
|
package/src/server.ts
CHANGED
|
@@ -14,22 +14,22 @@ const INJECTED_SCRIPT = `
|
|
|
14
14
|
<!-- Code injected by auto-server -->
|
|
15
15
|
<script>
|
|
16
16
|
(function() {
|
|
17
|
-
console.log('[
|
|
17
|
+
console.log('[one-server-4-all] Connected to hot reload');
|
|
18
18
|
const evtSource = new EventSource('/_hot_server_sse');
|
|
19
19
|
evtSource.onmessage = function(event) {
|
|
20
20
|
try {
|
|
21
21
|
const data = JSON.parse(event.data);
|
|
22
22
|
if (data.type === 'css') {
|
|
23
|
-
console.log('[
|
|
23
|
+
console.log('[one-server-4-all] CSS changed, injecting...');
|
|
24
24
|
injectCSS(data.file);
|
|
25
25
|
} else {
|
|
26
|
-
console.log('[
|
|
26
|
+
console.log('[one-server-4-all] Reloading...');
|
|
27
27
|
window.location.reload();
|
|
28
28
|
}
|
|
29
29
|
} catch (e) {
|
|
30
30
|
// Fallback para compatibilidade
|
|
31
31
|
if (event.data === 'reload') {
|
|
32
|
-
console.log('[
|
|
32
|
+
console.log('[one-server-4-all] Reloading...');
|
|
33
33
|
window.location.reload();
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -46,13 +46,13 @@ const INJECTED_SCRIPT = `
|
|
|
46
46
|
// Força reload do CSS adicionando/removendo timestamp
|
|
47
47
|
const newHref = href.split('?')[0] + '?v=' + timestamp;
|
|
48
48
|
link.setAttribute('href', newHref);
|
|
49
|
-
console.log('[
|
|
49
|
+
console.log('[one-server-4-all] CSS injected:', filePath);
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
evtSource.onerror = function() {
|
|
55
|
-
console.log('[
|
|
55
|
+
console.log('[one-server-4-all] Disconnected. Retrying...');
|
|
56
56
|
};
|
|
57
57
|
})();
|
|
58
58
|
</script>
|
|
@@ -383,7 +383,7 @@ export class HotServer {
|
|
|
383
383
|
const gray = (text: string) => `\x1b[90m${text}\x1b[0m`;
|
|
384
384
|
|
|
385
385
|
console.log(
|
|
386
|
-
`\n ${bold(cyan("
|
|
386
|
+
`\n ${bold(cyan("one-server-4-all"))} ${cyan("v" + version)} ${gray(
|
|
387
387
|
"ready in"
|
|
388
388
|
)} ${bold(green(readyTime + " ms"))}\n`
|
|
389
389
|
);
|
|
@@ -656,7 +656,7 @@ export class HotServer {
|
|
|
656
656
|
</div>
|
|
657
657
|
|
|
658
658
|
<div class="back">
|
|
659
|
-
Servido por <strong>purecore-
|
|
659
|
+
Servido por <strong>purecore-one-server-4-all</strong>
|
|
660
660
|
</div>
|
|
661
661
|
</div>
|
|
662
662
|
</body>
|