hightjs 0.4.0 → 0.5.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/README.md +42 -126
- package/dist/bin/hightjs.js +51 -23
- package/dist/builder.js +139 -4
- package/dist/client/DefaultNotFound.d.ts +1 -1
- package/dist/client/DefaultNotFound.js +72 -46
- package/dist/client/client.d.ts +3 -0
- package/dist/{client.js → client/client.js} +4 -4
- package/dist/client/entry.client.js +39 -29
- package/dist/global/global.d.ts +117 -0
- package/dist/{auth/types.js → global/global.js} +0 -1
- package/dist/helpers.js +80 -2
- package/dist/hotReload.js +2 -2
- package/dist/index.js +16 -16
- package/dist/loaders.d.ts +1 -0
- package/dist/loaders.js +46 -0
- package/dist/renderer.js +158 -4
- package/dist/types.d.ts +44 -0
- package/package.json +37 -31
- package/src/bin/hightjs.js +59 -29
- package/src/builder.js +163 -4
- package/src/client/DefaultNotFound.tsx +88 -53
- package/src/{client.ts → client/client.ts} +4 -3
- package/src/client/entry.client.tsx +44 -29
- package/src/global/global.ts +171 -0
- package/src/helpers.ts +91 -2
- package/src/hotReload.ts +2 -2
- package/src/index.ts +2 -0
- package/src/loaders.js +53 -0
- package/src/renderer.tsx +162 -4
- package/src/types.ts +51 -0
- package/.idea/HightJS.iml +0 -9
- package/.idea/copilot.data.migration.agent.xml +0 -6
- package/.idea/copilot.data.migration.ask.xml +0 -6
- package/.idea/copilot.data.migration.ask2agent.xml +0 -6
- package/.idea/copilot.data.migration.edit.xml +0 -6
- package/.idea/copilotDiffState.xml +0 -67
- package/.idea/inspectionProfiles/Project_Default.xml +0 -13
- package/.idea/libraries/test_package.xml +0 -9
- package/.idea/libraries/ts_commonjs_default_export.xml +0 -9
- package/.idea/misc.xml +0 -7
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/dist/auth/client.d.ts +0 -24
- package/dist/auth/client.js +0 -146
- package/dist/auth/components.d.ts +0 -29
- package/dist/auth/components.js +0 -100
- package/dist/auth/core.d.ts +0 -55
- package/dist/auth/core.js +0 -189
- package/dist/auth/index.d.ts +0 -7
- package/dist/auth/index.js +0 -45
- package/dist/auth/jwt.d.ts +0 -41
- package/dist/auth/jwt.js +0 -185
- package/dist/auth/providers/credentials.d.ts +0 -60
- package/dist/auth/providers/credentials.js +0 -97
- package/dist/auth/providers/discord.d.ts +0 -63
- package/dist/auth/providers/discord.js +0 -190
- package/dist/auth/providers/google.d.ts +0 -63
- package/dist/auth/providers/google.js +0 -186
- package/dist/auth/providers/index.d.ts +0 -2
- package/dist/auth/providers/index.js +0 -35
- package/dist/auth/providers.d.ts +0 -3
- package/dist/auth/providers.js +0 -26
- package/dist/auth/react/index.d.ts +0 -6
- package/dist/auth/react/index.js +0 -48
- package/dist/auth/react.d.ts +0 -22
- package/dist/auth/react.js +0 -199
- package/dist/auth/routes.d.ts +0 -16
- package/dist/auth/routes.js +0 -152
- package/dist/auth/types.d.ts +0 -76
- package/dist/client.d.ts +0 -3
- package/docs/README.md +0 -58
- package/docs/arquivos-especiais.md +0 -10
- package/docs/autenticacao.md +0 -212
- package/docs/checklist.md +0 -9
- package/docs/cli.md +0 -72
- package/docs/config.md +0 -216
- package/docs/estrutura.md +0 -20
- package/docs/faq.md +0 -10
- package/docs/hot-reload.md +0 -5
- package/docs/integracoes.md +0 -240
- package/docs/middlewares.md +0 -73
- package/docs/rotas-backend.md +0 -45
- package/docs/rotas-frontend.md +0 -66
- package/docs/seguranca.md +0 -8
- package/docs/websocket.md +0 -45
- package/example/certs/cert.pem +0 -20
- package/example/certs/key.pem +0 -27
- package/example/hightjs.config.ts +0 -87
- package/example/package-lock.json +0 -1174
- package/example/package.json +0 -26
- package/example/postcss.config.js +0 -8
- package/example/src/backend/auth.ts +0 -42
- package/example/src/backend/routes/auth.ts +0 -3
- package/example/src/backend/routes/version.ts +0 -13
- package/example/src/web/components/Home.tsx +0 -140
- package/example/src/web/components/LoginPage.tsx +0 -149
- package/example/src/web/globals.css +0 -5
- package/example/src/web/layout.tsx +0 -100
- package/example/src/web/routes/index.tsx +0 -13
- package/example/src/web/routes/login.tsx +0 -30
- package/example/tailwind.config.js +0 -12
- package/example/tsconfig.json +0 -15
- package/src/auth/client.ts +0 -171
- package/src/auth/components.tsx +0 -125
- package/src/auth/core.ts +0 -215
- package/src/auth/index.ts +0 -25
- package/src/auth/jwt.ts +0 -210
- package/src/auth/providers/credentials.ts +0 -139
- package/src/auth/providers/discord.ts +0 -239
- package/src/auth/providers/google.ts +0 -234
- package/src/auth/providers/index.ts +0 -20
- package/src/auth/providers.ts +0 -20
- package/src/auth/react/index.ts +0 -25
- package/src/auth/react.tsx +0 -234
- package/src/auth/routes.ts +0 -183
- package/src/auth/types.ts +0 -108
- package/tsconfig.json +0 -17
|
@@ -56,14 +56,48 @@ const clientRouter_1 = require("./clientRouter");
|
|
|
56
56
|
function App({ componentMap, routes, initialComponentPath, initialParams, layoutComponent }) {
|
|
57
57
|
// Estado que guarda o componente a ser renderizado atualmente
|
|
58
58
|
const [hmrTimestamp, setHmrTimestamp] = (0, react_1.useState)(Date.now());
|
|
59
|
+
// Helper para encontrar rota baseado no path
|
|
60
|
+
const findRouteForPath = (0, react_1.useCallback)((path) => {
|
|
61
|
+
for (const route of routes) {
|
|
62
|
+
const regexPattern = route.pattern
|
|
63
|
+
// [[...param]] → opcional catch-all
|
|
64
|
+
.replace(/\[\[\.\.\.(\w+)\]\]/g, '(?<$1>.+)?')
|
|
65
|
+
// [...param] → obrigatório catch-all
|
|
66
|
+
.replace(/\[\.\.\.(\w+)\]/g, '(?<$1>.+)')
|
|
67
|
+
// /[[param]] → opcional com barra também opcional
|
|
68
|
+
.replace(/\/\[\[(\w+)\]\]/g, '(?:/(?<$1>[^/]+))?')
|
|
69
|
+
// [[param]] → segmento opcional (sem barra anterior)
|
|
70
|
+
.replace(/\[\[(\w+)\]\]/g, '(?<$1>[^/]+)?')
|
|
71
|
+
// [param] → segmento obrigatório
|
|
72
|
+
.replace(/\[(\w+)\]/g, '(?<$1>[^/]+)');
|
|
73
|
+
const regex = new RegExp(`^${regexPattern}/?$`);
|
|
74
|
+
const match = path.match(regex);
|
|
75
|
+
if (match) {
|
|
76
|
+
return {
|
|
77
|
+
componentPath: route.componentPath,
|
|
78
|
+
params: match.groups || {}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}, [routes]);
|
|
84
|
+
// Inicializa o componente e params baseado na URL ATUAL (não no initialComponentPath)
|
|
59
85
|
const [CurrentPageComponent, setCurrentPageComponent] = (0, react_1.useState)(() => {
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
86
|
+
// Pega a rota atual da URL
|
|
87
|
+
const currentPath = window.location.pathname;
|
|
88
|
+
const match = findRouteForPath(currentPath);
|
|
89
|
+
if (match) {
|
|
90
|
+
return componentMap[match.componentPath];
|
|
63
91
|
}
|
|
64
|
-
|
|
92
|
+
// Se não encontrou rota, retorna null para mostrar 404
|
|
93
|
+
return null;
|
|
94
|
+
});
|
|
95
|
+
const [params, setParams] = (0, react_1.useState)(() => {
|
|
96
|
+
// Pega os params da URL atual
|
|
97
|
+
const currentPath = window.location.pathname;
|
|
98
|
+
const match = findRouteForPath(currentPath);
|
|
99
|
+
return match ? match.params : {};
|
|
65
100
|
});
|
|
66
|
-
const [params, setParams] = (0, react_1.useState)(initialParams);
|
|
67
101
|
// HMR: Escuta eventos de hot reload
|
|
68
102
|
(0, react_1.useEffect)(() => {
|
|
69
103
|
// Ativa o sistema de HMR
|
|
@@ -120,30 +154,6 @@ function App({ componentMap, routes, initialComponentPath, initialParams, layout
|
|
|
120
154
|
window.removeEventListener('hmr:component-update', handleHMRUpdate);
|
|
121
155
|
};
|
|
122
156
|
}, []);
|
|
123
|
-
const findRouteForPath = (0, react_1.useCallback)((path) => {
|
|
124
|
-
for (const route of routes) {
|
|
125
|
-
const regexPattern = route.pattern
|
|
126
|
-
// [[...param]] → opcional catch-all
|
|
127
|
-
.replace(/\[\[\.\.\.(\w+)\]\]/g, '(?<$1>.+)?')
|
|
128
|
-
// [...param] → obrigatório catch-all
|
|
129
|
-
.replace(/\[\.\.\.(\w+)\]/g, '(?<$1>.+)')
|
|
130
|
-
// /[[param]] → opcional com barra também opcional
|
|
131
|
-
.replace(/\/\[\[(\w+)\]\]/g, '(?:/(?<$1>[^/]+))?')
|
|
132
|
-
// [[param]] → segmento opcional (sem barra anterior)
|
|
133
|
-
.replace(/\[\[(\w+)\]\]/g, '(?<$1>[^/]+)?')
|
|
134
|
-
// [param] → segmento obrigatório
|
|
135
|
-
.replace(/\[(\w+)\]/g, '(?<$1>[^/]+)');
|
|
136
|
-
const regex = new RegExp(`^${regexPattern}/?$`);
|
|
137
|
-
const match = path.match(regex);
|
|
138
|
-
if (match) {
|
|
139
|
-
return {
|
|
140
|
-
componentPath: route.componentPath,
|
|
141
|
-
params: match.groups || {}
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return null;
|
|
146
|
-
}, [routes]);
|
|
147
157
|
const updateRoute = (0, react_1.useCallback)(() => {
|
|
148
158
|
const currentPath = clientRouter_1.router.pathname;
|
|
149
159
|
const match = findRouteForPath(currentPath);
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type declarations for asset imports
|
|
3
|
+
* This allows TypeScript to understand imports of various file types
|
|
4
|
+
*/
|
|
5
|
+
declare module "*.md" {
|
|
6
|
+
const content: string;
|
|
7
|
+
export default content;
|
|
8
|
+
}
|
|
9
|
+
declare module "*.png" {
|
|
10
|
+
const src: string;
|
|
11
|
+
export default src;
|
|
12
|
+
}
|
|
13
|
+
declare module "*.jpg" {
|
|
14
|
+
const src: string;
|
|
15
|
+
export default src;
|
|
16
|
+
}
|
|
17
|
+
declare module "*.jpeg" {
|
|
18
|
+
const src: string;
|
|
19
|
+
export default src;
|
|
20
|
+
}
|
|
21
|
+
declare module "*.gif" {
|
|
22
|
+
const src: string;
|
|
23
|
+
export default src;
|
|
24
|
+
}
|
|
25
|
+
declare module "*.webp" {
|
|
26
|
+
const src: string;
|
|
27
|
+
export default src;
|
|
28
|
+
}
|
|
29
|
+
declare module "*.avif" {
|
|
30
|
+
const src: string;
|
|
31
|
+
export default src;
|
|
32
|
+
}
|
|
33
|
+
declare module "*.ico" {
|
|
34
|
+
const src: string;
|
|
35
|
+
export default src;
|
|
36
|
+
}
|
|
37
|
+
declare module "*.bmp" {
|
|
38
|
+
const src: string;
|
|
39
|
+
export default src;
|
|
40
|
+
}
|
|
41
|
+
declare module "*.tif" {
|
|
42
|
+
const src: string;
|
|
43
|
+
export default src;
|
|
44
|
+
}
|
|
45
|
+
declare module "*.tiff" {
|
|
46
|
+
const src: string;
|
|
47
|
+
export default src;
|
|
48
|
+
}
|
|
49
|
+
declare module "*.svg" {
|
|
50
|
+
const src: string;
|
|
51
|
+
export const svgContent: string;
|
|
52
|
+
export default src;
|
|
53
|
+
}
|
|
54
|
+
declare module "*.json" {
|
|
55
|
+
const value: any;
|
|
56
|
+
export default value;
|
|
57
|
+
}
|
|
58
|
+
declare module "*.txt" {
|
|
59
|
+
const content: string;
|
|
60
|
+
export default content;
|
|
61
|
+
}
|
|
62
|
+
declare module "*.woff" {
|
|
63
|
+
const src: string;
|
|
64
|
+
export default src;
|
|
65
|
+
}
|
|
66
|
+
declare module "*.woff2" {
|
|
67
|
+
const src: string;
|
|
68
|
+
export default src;
|
|
69
|
+
}
|
|
70
|
+
declare module "*.ttf" {
|
|
71
|
+
const src: string;
|
|
72
|
+
export default src;
|
|
73
|
+
}
|
|
74
|
+
declare module "*.otf" {
|
|
75
|
+
const src: string;
|
|
76
|
+
export default src;
|
|
77
|
+
}
|
|
78
|
+
declare module "*.eot" {
|
|
79
|
+
const src: string;
|
|
80
|
+
export default src;
|
|
81
|
+
}
|
|
82
|
+
declare module "*.mp3" {
|
|
83
|
+
const src: string;
|
|
84
|
+
export default src;
|
|
85
|
+
}
|
|
86
|
+
declare module "*.wav" {
|
|
87
|
+
const src: string;
|
|
88
|
+
export default src;
|
|
89
|
+
}
|
|
90
|
+
declare module "*.ogg" {
|
|
91
|
+
const src: string;
|
|
92
|
+
export default src;
|
|
93
|
+
}
|
|
94
|
+
declare module "*.m4a" {
|
|
95
|
+
const src: string;
|
|
96
|
+
export default src;
|
|
97
|
+
}
|
|
98
|
+
declare module "*.aac" {
|
|
99
|
+
const src: string;
|
|
100
|
+
export default src;
|
|
101
|
+
}
|
|
102
|
+
declare module "*.flac" {
|
|
103
|
+
const src: string;
|
|
104
|
+
export default src;
|
|
105
|
+
}
|
|
106
|
+
declare module "*.mp4" {
|
|
107
|
+
const src: string;
|
|
108
|
+
export default src;
|
|
109
|
+
}
|
|
110
|
+
declare module "*.webm" {
|
|
111
|
+
const src: string;
|
|
112
|
+
export default src;
|
|
113
|
+
}
|
|
114
|
+
declare module "*.ogv" {
|
|
115
|
+
const src: string;
|
|
116
|
+
export default src;
|
|
117
|
+
}
|
package/dist/helpers.js
CHANGED
|
@@ -64,6 +64,9 @@ const index_1 = __importStar(require("./index")); // Importando o tipo
|
|
|
64
64
|
const console_1 = __importStar(require("./api/console"));
|
|
65
65
|
const https_1 = __importDefault(require("https")); // <-- ADICIONAR
|
|
66
66
|
const fs_1 = __importDefault(require("fs")); // <-- ADICIONAR
|
|
67
|
+
// Registra loaders customizados para importar arquivos não-JS
|
|
68
|
+
const { registerLoaders } = require('./loaders');
|
|
69
|
+
registerLoaders();
|
|
67
70
|
// --- Helpers ---
|
|
68
71
|
/**
|
|
69
72
|
* Encontra o IP externo local (rede)
|
|
@@ -164,9 +167,74 @@ async function loadHightConfig(projectDir, phase) {
|
|
|
164
167
|
}
|
|
165
168
|
}
|
|
166
169
|
/**
|
|
167
|
-
*
|
|
168
|
-
*
|
|
170
|
+
* Aplica headers CORS na resposta baseado na configuração.
|
|
171
|
+
* @param req Requisição HTTP
|
|
172
|
+
* @param res Resposta HTTP
|
|
173
|
+
* @param corsConfig Configuração de CORS
|
|
174
|
+
* @returns true se a requisição foi finalizada (OPTIONS), false caso contrário
|
|
169
175
|
*/
|
|
176
|
+
function applyCors(req, res, corsConfig) {
|
|
177
|
+
if (!corsConfig || !corsConfig.enabled) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
const origin = req.headers.origin || req.headers.referer;
|
|
181
|
+
// Verifica se a origem é permitida
|
|
182
|
+
let allowOrigin = false;
|
|
183
|
+
if (corsConfig.origin === '*') {
|
|
184
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
185
|
+
allowOrigin = true;
|
|
186
|
+
}
|
|
187
|
+
else if (typeof corsConfig.origin === 'string' && origin === corsConfig.origin) {
|
|
188
|
+
res.setHeader('Access-Control-Allow-Origin', corsConfig.origin);
|
|
189
|
+
allowOrigin = true;
|
|
190
|
+
}
|
|
191
|
+
else if (Array.isArray(corsConfig.origin) && origin && corsConfig.origin.includes(origin)) {
|
|
192
|
+
res.setHeader('Access-Control-Allow-Origin', origin);
|
|
193
|
+
allowOrigin = true;
|
|
194
|
+
}
|
|
195
|
+
else if (typeof corsConfig.origin === 'function' && origin) {
|
|
196
|
+
try {
|
|
197
|
+
if (corsConfig.origin(origin)) {
|
|
198
|
+
res.setHeader('Access-Control-Allow-Origin', origin);
|
|
199
|
+
allowOrigin = true;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
console_1.default.warn(`${console_1.Colors.FgYellow}[CORS]${console_1.Colors.Reset} Error validating origin: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Se a origem não for permitida e não for wildcard, não aplica outros headers
|
|
207
|
+
if (!allowOrigin && corsConfig.origin !== '*') {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
// Credenciais (não pode ser usado com origin: '*')
|
|
211
|
+
if (corsConfig.credentials && corsConfig.origin !== '*') {
|
|
212
|
+
res.setHeader('Access-Control-Allow-Credentials', 'true');
|
|
213
|
+
}
|
|
214
|
+
// Métodos permitidos
|
|
215
|
+
const methods = corsConfig.methods || ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'];
|
|
216
|
+
res.setHeader('Access-Control-Allow-Methods', methods.join(', '));
|
|
217
|
+
// Headers permitidos
|
|
218
|
+
const allowedHeaders = corsConfig.allowedHeaders || ['Content-Type', 'Authorization'];
|
|
219
|
+
res.setHeader('Access-Control-Allow-Headers', allowedHeaders.join(', '));
|
|
220
|
+
// Headers expostos
|
|
221
|
+
if (corsConfig.exposedHeaders && corsConfig.exposedHeaders.length > 0) {
|
|
222
|
+
res.setHeader('Access-Control-Expose-Headers', corsConfig.exposedHeaders.join(', '));
|
|
223
|
+
}
|
|
224
|
+
// Max age para cache de preflight
|
|
225
|
+
const maxAge = corsConfig.maxAge !== undefined ? corsConfig.maxAge : 86400;
|
|
226
|
+
res.setHeader('Access-Control-Max-Age', maxAge.toString());
|
|
227
|
+
// Responde requisições OPTIONS (preflight)
|
|
228
|
+
if (req.method === 'OPTIONS') {
|
|
229
|
+
res.statusCode = 204; // No Content
|
|
230
|
+
res.end();
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Middleware para parsing do body com proteções de segurança (versão melhorada).
|
|
237
|
+
*/
|
|
170
238
|
const parseBody = (req) => {
|
|
171
239
|
// Constantes para limites de segurança
|
|
172
240
|
const MAX_BODY_SIZE = 10 * 1024 * 1024; // 10MB limite total
|
|
@@ -254,6 +322,16 @@ async function initNativeServer(hwebApp, options, port, hostname) {
|
|
|
254
322
|
const requestStartTime = Date.now();
|
|
255
323
|
const method = req.method || 'GET';
|
|
256
324
|
const url = req.url || '/';
|
|
325
|
+
// Aplica CORS se configurado
|
|
326
|
+
const corsHandled = applyCors(req, res, hightConfig.cors);
|
|
327
|
+
if (corsHandled) {
|
|
328
|
+
// Requisição OPTIONS foi respondida pelo CORS
|
|
329
|
+
if (hightConfig.accessLogging) {
|
|
330
|
+
const duration = Date.now() - requestStartTime;
|
|
331
|
+
console_1.default.logCustomLevel('OPTIONS', true, console_1.Colors.BgMagenta, `${url} ${console_1.Colors.FgGreen}204${console_1.Colors.Reset} ${console_1.Colors.FgGray}${duration}ms${console_1.Colors.Reset} ${console_1.Colors.FgCyan}[CORS]${console_1.Colors.Reset}`);
|
|
332
|
+
}
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
257
335
|
// Configurações de segurança básicas
|
|
258
336
|
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
259
337
|
res.setHeader('X-Frame-Options', 'DENY');
|
package/dist/hotReload.js
CHANGED
|
@@ -195,8 +195,7 @@ class HotReloadManager {
|
|
|
195
195
|
filePath.includes('not-found.tsx') ||
|
|
196
196
|
filePath.endsWith('.tsx') ||
|
|
197
197
|
filePath.endsWith('.jsx');
|
|
198
|
-
const isBackendFile = filePath.includes(path.join('src', 'backend'))
|
|
199
|
-
(filePath.includes(path.join('src', 'web')) && !isFrontendFile);
|
|
198
|
+
const isBackendFile = filePath.includes(path.join('src', 'backend')) && !isFrontendFile;
|
|
200
199
|
// Limpa o cache do arquivo alterado
|
|
201
200
|
(0, router_1.clearFileCache)(filePath);
|
|
202
201
|
this.clearBackendCache(filePath);
|
|
@@ -214,6 +213,7 @@ class HotReloadManager {
|
|
|
214
213
|
setTimeout(() => reject(new Error('Build timeout')), 30000);
|
|
215
214
|
});
|
|
216
215
|
try {
|
|
216
|
+
this.frontendChangeCallback?.();
|
|
217
217
|
await Promise.race([buildPromise, timeoutPromise]);
|
|
218
218
|
console_1.default.logWithout(console_1.Levels.INFO, console_1.Colors.BgRed, `✅ Build complete, reloading frontend...`);
|
|
219
219
|
this.frontendChangeCallback?.();
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This file is part of the HightJS Project.
|
|
4
|
+
* Copyright (c) 2025 itsmuzin
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
2
18
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
19
|
if (k2 === undefined) k2 = k;
|
|
4
20
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -38,22 +54,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
54
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
55
|
exports.app = exports.FrameworkAdapterFactory = exports.FastifyAdapter = exports.ExpressAdapter = exports.HightJSResponse = exports.HightJSRequest = void 0;
|
|
40
56
|
exports.default = hweb;
|
|
41
|
-
/*
|
|
42
|
-
* This file is part of the HightJS Project.
|
|
43
|
-
* Copyright (c) 2025 itsmuzin
|
|
44
|
-
*
|
|
45
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
46
|
-
* you may not use this file except in compliance with the License.
|
|
47
|
-
* You may obtain a copy of the License at
|
|
48
|
-
*
|
|
49
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
50
|
-
*
|
|
51
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
52
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
53
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
54
|
-
* See the License for the specific language governing permissions and
|
|
55
|
-
* limitations under the License.
|
|
56
|
-
*/
|
|
57
57
|
const path_1 = __importDefault(require("path"));
|
|
58
58
|
const fs_1 = __importDefault(require("fs"));
|
|
59
59
|
const express_1 = require("./adapters/express");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export = filename;
|
package/dist/loaders.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This file is part of the HightJS Project.
|
|
4
|
+
* Copyright (c) 2025 itsmuzin
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
const fs = require('fs');
|
|
19
|
+
/**
|
|
20
|
+
* Registra loaders customizados para Node.js
|
|
21
|
+
* Permite importar arquivos não-JS diretamente no servidor
|
|
22
|
+
*/
|
|
23
|
+
function registerLoaders() {
|
|
24
|
+
// Loader para arquivos Markdown (.md)
|
|
25
|
+
require.extensions['.md'] = function (module, filename) {
|
|
26
|
+
const content = fs.readFileSync(filename, 'utf8');
|
|
27
|
+
module.exports = content;
|
|
28
|
+
};
|
|
29
|
+
// Loader para arquivos de texto (.txt)
|
|
30
|
+
require.extensions['.txt'] = function (module, filename) {
|
|
31
|
+
const content = fs.readFileSync(filename, 'utf8');
|
|
32
|
+
module.exports = content;
|
|
33
|
+
};
|
|
34
|
+
// Loader para arquivos JSON (já existe nativamente, mas garantimos consistência)
|
|
35
|
+
// require.extensions['.json'] já existe
|
|
36
|
+
// Loader para imagens - retorna o caminho do arquivo
|
|
37
|
+
const imageExtensions = ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.avif', '.ico', '.bmp', '.svg'];
|
|
38
|
+
imageExtensions.forEach(ext => {
|
|
39
|
+
require.extensions[ext] = function (module, filename) {
|
|
40
|
+
// No servidor, retornamos o caminho do arquivo
|
|
41
|
+
// O frontend usará o plugin do esbuild para converter em base64
|
|
42
|
+
module.exports = filename;
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
module.exports = { registerLoaders };
|
package/dist/renderer.js
CHANGED
|
@@ -178,6 +178,11 @@ ${hotReloadScript}
|
|
|
178
178
|
function getJavaScriptFiles(req) {
|
|
179
179
|
const projectDir = process.cwd();
|
|
180
180
|
const distDir = path_1.default.join(projectDir, '.hight');
|
|
181
|
+
// Verifica se o diretório de build existe
|
|
182
|
+
if (!fs_1.default.existsSync(distDir)) {
|
|
183
|
+
// Diretório não existe - build ainda não foi executado
|
|
184
|
+
return getBuildingHTML();
|
|
185
|
+
}
|
|
181
186
|
try {
|
|
182
187
|
// Verifica se existe um manifesto de chunks (gerado pelo ESBuild com splitting)
|
|
183
188
|
const manifestPath = path_1.default.join(distDir, 'manifest.json');
|
|
@@ -188,6 +193,10 @@ function getJavaScriptFiles(req) {
|
|
|
188
193
|
.filter((file) => file.endsWith('.js'))
|
|
189
194
|
.map((file) => `<script src="/_hight/${file}"></script>`)
|
|
190
195
|
.join('');
|
|
196
|
+
// Se não há arquivos JS no manifesto, build em andamento
|
|
197
|
+
if (!scripts) {
|
|
198
|
+
return getBuildingHTML();
|
|
199
|
+
}
|
|
191
200
|
return scripts;
|
|
192
201
|
}
|
|
193
202
|
else {
|
|
@@ -214,13 +223,158 @@ function getJavaScriptFiles(req) {
|
|
|
214
223
|
.join('');
|
|
215
224
|
}
|
|
216
225
|
else {
|
|
217
|
-
//
|
|
218
|
-
return
|
|
226
|
+
// Nenhum arquivo JS encontrado - build em andamento ou erro
|
|
227
|
+
return getBuildingHTML();
|
|
219
228
|
}
|
|
220
229
|
}
|
|
221
230
|
}
|
|
222
231
|
catch (error) {
|
|
223
|
-
//
|
|
224
|
-
return
|
|
232
|
+
// Erro ao ler diretório - build em andamento ou erro
|
|
233
|
+
return getBuildingHTML();
|
|
225
234
|
}
|
|
226
235
|
}
|
|
236
|
+
// Função para retornar HTML de "Build em andamento" com auto-refresh
|
|
237
|
+
function getBuildingHTML() {
|
|
238
|
+
return `
|
|
239
|
+
<style>
|
|
240
|
+
/*
|
|
241
|
+
* Estilo combinado:
|
|
242
|
+
* - Tema (light/dark) adaptativo como o Next.js
|
|
243
|
+
* - Ícone personalizado
|
|
244
|
+
* - Efeito Glassmorphism para o card
|
|
245
|
+
*/
|
|
246
|
+
|
|
247
|
+
html, body {
|
|
248
|
+
margin: 0;
|
|
249
|
+
padding: 0;
|
|
250
|
+
width: 100%;
|
|
251
|
+
height: 100%;
|
|
252
|
+
font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
|
|
253
|
+
-webkit-font-smoothing: antialiased;
|
|
254
|
+
-moz-osx-font-smoothing: grayscale;
|
|
255
|
+
box-sizing: border-box;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
*, *:before, *:after {
|
|
259
|
+
box-sizing: inherit;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/* Tema Claro (Default) */
|
|
263
|
+
body {
|
|
264
|
+
color: #000;
|
|
265
|
+
background: linear-gradient(to bottom, #e9e9e9, #ffffff);
|
|
266
|
+
background-attachment: fixed;
|
|
267
|
+
|
|
268
|
+
display: flex;
|
|
269
|
+
align-items: center;
|
|
270
|
+
justify-content: center;
|
|
271
|
+
min-height: 100vh;
|
|
272
|
+
text-align: center;
|
|
273
|
+
padding: 20px;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/* Contêiner com Glassmorphism */
|
|
277
|
+
.building-container {
|
|
278
|
+
width: 100%;
|
|
279
|
+
max-width: 500px;
|
|
280
|
+
padding: 40px 50px;
|
|
281
|
+
|
|
282
|
+
/* Efeito de vidro */
|
|
283
|
+
background: rgba(255, 255, 255, 0.15); /* Mais transparente no modo claro */
|
|
284
|
+
backdrop-filter: blur(12px); /* Um pouco mais de blur */
|
|
285
|
+
-webkit-backdrop-filter: blur(12px);
|
|
286
|
+
|
|
287
|
+
border-radius: 16px;
|
|
288
|
+
border: 1px solid rgba(255, 255, 255, 0.3); /* Borda mais visível no claro */
|
|
289
|
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1); /* Sombra mais leve no claro */
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/* Ícone */
|
|
293
|
+
.building-icon {
|
|
294
|
+
width: 70px; /* Tamanho do ícone */
|
|
295
|
+
height: 70px;
|
|
296
|
+
margin-bottom: 20px; /* Espaço abaixo do ícone */
|
|
297
|
+
vertical-align: middle;
|
|
298
|
+
filter: drop-shadow(0 0 5px rgba(0,0,0,0.1)); /* Leve sombra para destacar */
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/* Título */
|
|
302
|
+
.building-title {
|
|
303
|
+
font-size: 2.8rem;
|
|
304
|
+
font-weight: 700;
|
|
305
|
+
margin-top: 0; /* Ajusta a margem superior após o ícone */
|
|
306
|
+
margin-bottom: 20px;
|
|
307
|
+
text-shadow: 0 0 10px rgba(0, 0, 0, 0.05); /* Sombra de texto sutil */
|
|
308
|
+
color: inherit; /* Garante que a cor se adapta ao tema */
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/* Texto de apoio */
|
|
312
|
+
.building-text {
|
|
313
|
+
font-size: 1.15rem;
|
|
314
|
+
margin-bottom: 35px;
|
|
315
|
+
font-weight: 400;
|
|
316
|
+
opacity: 0.9;
|
|
317
|
+
color: inherit; /* Garante que a cor se adapta ao tema */
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/* Spinner adaptado para light/dark */
|
|
321
|
+
.spinner {
|
|
322
|
+
width: 50px;
|
|
323
|
+
height: 50px;
|
|
324
|
+
margin: 0 auto;
|
|
325
|
+
border-radius: 50%;
|
|
326
|
+
|
|
327
|
+
/* Estilo para Modo Claro */
|
|
328
|
+
border: 5px solid rgba(0, 0, 0, 0.1);
|
|
329
|
+
border-top-color: #000;
|
|
330
|
+
|
|
331
|
+
animation: spin 1s linear infinite;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/* Animação de rotação */
|
|
335
|
+
@keyframes spin {
|
|
336
|
+
0% { transform: rotate(0deg); }
|
|
337
|
+
100% { transform: rotate(360deg); }
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/* Tema Escuro (via @media query) */
|
|
341
|
+
@media (prefers-color-scheme: dark) {
|
|
342
|
+
body {
|
|
343
|
+
color: #fff;
|
|
344
|
+
background: linear-gradient(to bottom, #222, #000);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
.building-container {
|
|
348
|
+
background: rgba(255, 255, 255, 0.05); /* Mais opaco no modo escuro */
|
|
349
|
+
border: 1px solid rgba(255, 255, 255, 0.1); /* Borda mais sutil no escuro */
|
|
350
|
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3); /* Sombra mais forte no escuro */
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
.building-title {
|
|
354
|
+
text-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
.building-icon {
|
|
358
|
+
filter: drop-shadow(0 0 5px rgba(255,255,255,0.1));
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
.spinner {
|
|
362
|
+
border: 5px solid rgba(255, 255, 255, 0.1);
|
|
363
|
+
border-top-color: #fff;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
</style>
|
|
367
|
+
<div class="building-container">
|
|
368
|
+
<!-- Ícone da imagem --><img src="https://repository-images.githubusercontent.com/1069175740/e5c59d3a-e1fd-446c-a89f-785ed08f6a16" alt="HightJS Logo" class="building-icon">
|
|
369
|
+
|
|
370
|
+
<div class="building-title">HightJS</div>
|
|
371
|
+
<div class="building-text">Build in progress...</div>
|
|
372
|
+
<div class="spinner"></div>
|
|
373
|
+
</div>
|
|
374
|
+
<script>
|
|
375
|
+
// Auto-refresh a cada 2 segundos para verificar se o build terminou
|
|
376
|
+
setTimeout(() => {
|
|
377
|
+
window.location.reload();
|
|
378
|
+
}, 2000);
|
|
379
|
+
</script>`;
|
|
380
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -67,6 +67,50 @@ export interface HightConfig {
|
|
|
67
67
|
* Padrão: false
|
|
68
68
|
*/
|
|
69
69
|
accessLogging?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Configurações de CORS (Cross-Origin Resource Sharing).
|
|
72
|
+
* Define quais origens podem acessar seus recursos.
|
|
73
|
+
*/
|
|
74
|
+
cors?: {
|
|
75
|
+
/**
|
|
76
|
+
* Origens permitidas. Pode ser:
|
|
77
|
+
* - Uma string específica: 'https://exemplo.com'
|
|
78
|
+
* - Um array de strings: ['https://exemplo.com', 'https://outro.com']
|
|
79
|
+
* - Um wildcard: '*' (permite todas as origens - não recomendado em produção)
|
|
80
|
+
* - Uma função que retorna boolean: (origin) => origin.endsWith('.exemplo.com')
|
|
81
|
+
*/
|
|
82
|
+
origin?: string | string[] | ((origin: string) => boolean);
|
|
83
|
+
/**
|
|
84
|
+
* Métodos HTTP permitidos.
|
|
85
|
+
* Padrão: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS']
|
|
86
|
+
*/
|
|
87
|
+
methods?: string[];
|
|
88
|
+
/**
|
|
89
|
+
* Headers permitidos nas requisições.
|
|
90
|
+
* Padrão: ['Content-Type', 'Authorization']
|
|
91
|
+
*/
|
|
92
|
+
allowedHeaders?: string[];
|
|
93
|
+
/**
|
|
94
|
+
* Headers que serão expostos ao cliente.
|
|
95
|
+
* Padrão: []
|
|
96
|
+
*/
|
|
97
|
+
exposedHeaders?: string[];
|
|
98
|
+
/**
|
|
99
|
+
* Permite o envio de credenciais (cookies, headers de autenticação).
|
|
100
|
+
* Padrão: false
|
|
101
|
+
*/
|
|
102
|
+
credentials?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Tempo em segundos que o navegador deve cachear a resposta preflight.
|
|
105
|
+
* Padrão: 86400 (24 horas)
|
|
106
|
+
*/
|
|
107
|
+
maxAge?: number;
|
|
108
|
+
/**
|
|
109
|
+
* Habilita ou desabilita completamente o CORS.
|
|
110
|
+
* Padrão: false
|
|
111
|
+
*/
|
|
112
|
+
enabled?: boolean;
|
|
113
|
+
};
|
|
70
114
|
}
|
|
71
115
|
/**
|
|
72
116
|
* Tipo da função de configuração que pode ser exportada no hightjs.config.js
|