forgegit 1.3.0 → 1.4.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/.forge/commands/.gitkeep +0 -0
- package/.forge/commands/abrir.cmd +51 -0
- package/.forge/commands/auditar.cmd +340 -0
- package/.forge/commands/historial.cmd +85 -0
- package/.forge/commands/push.cmd +97 -0
- package/.forge/commands/save.cmd +73 -0
- package/.forge/commands/snapshots.cmd +329 -0
- package/.forge/init.cmd +200 -0
- package/.forge/lib/.gitkeep +0 -0
- package/.forge/lib/git-ops.cmd +92 -0
- package/.forge/lib/templates.cmd +98 -0
- package/.forge/lib/ui.cmd +59 -0
- package/.forge/templates/.gitkeep +0 -0
- package/.forge/templates/abrir.cmd.tpl +51 -0
- package/.forge/templates/auditar.cmd.tpl +340 -0
- package/.forge/templates/forge.cmd.tpl +114 -0
- package/.forge/templates/gitignore.tpl +78 -0
- package/.forge/templates/historial.cmd.tpl +85 -0
- package/.forge/templates/push.cmd.tpl +97 -0
- package/.forge/templates/readme.md.tpl +34 -0
- package/.forge/templates/save.cmd.tpl +73 -0
- package/.forge/templates/serve-static.js +86 -0
- package/.forge/templates/serve.cmd.tpl +209 -0
- package/.forge/templates/snapshots.cmd.tpl +329 -0
- package/MANUAL.md +61 -68
- package/config.cmd +14 -14
- package/forge.cmd +114 -0
- package/init.cmd +199 -190
- package/lib/git-ops.cmd +91 -91
- package/lib/templates.cmd +98 -97
- package/lib/ui.cmd +58 -57
- package/package.json +38 -36
- package/templates/forge.cmd.tpl +6 -2
- package/templates/serve-static.js +86 -0
- package/templates/serve.cmd.tpl +209 -0
package/lib/templates.cmd
CHANGED
|
@@ -1,97 +1,98 @@
|
|
|
1
|
-
@echo off
|
|
2
|
-
REM ============================================================
|
|
3
|
-
REM forge-git / lib/templates.cmd
|
|
4
|
-
REM Copies templates from templates/ to destinations
|
|
5
|
-
REM ============================================================
|
|
6
|
-
|
|
7
|
-
if "%~1"=="write_gitignore" goto :write_gitignore
|
|
8
|
-
if "%~1"=="write_readme" goto :write_readme
|
|
9
|
-
if "%~1"=="write_forge" goto :write_forge
|
|
10
|
-
if "%~1"=="write_save" goto :write_save
|
|
11
|
-
if "%~1"=="write_push" goto :write_push
|
|
12
|
-
if "%~1"=="write_snapshots" goto :write_snapshots
|
|
13
|
-
if "%~1"=="write_historial" goto :write_historial
|
|
14
|
-
if "%~1"=="write_abrir" goto :write_abrir
|
|
15
|
-
if "%~1"=="write_auditar" goto :write_auditar
|
|
16
|
-
goto :
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
:write_gitignore
|
|
20
|
-
call :copy_root "gitignore.tpl" ".gitignore"
|
|
21
|
-
goto :eof
|
|
22
|
-
|
|
23
|
-
:write_readme
|
|
24
|
-
call :apply_root "readme.md.tpl" "README.md"
|
|
25
|
-
goto :eof
|
|
26
|
-
|
|
27
|
-
:write_forge
|
|
28
|
-
call :copy_root "forge.cmd.tpl" "forge.cmd"
|
|
29
|
-
goto :eof
|
|
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
|
-
set "
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
1
|
+
@echo off
|
|
2
|
+
REM ============================================================
|
|
3
|
+
REM forge-git / lib/templates.cmd
|
|
4
|
+
REM Copies templates from templates/ to destinations
|
|
5
|
+
REM ============================================================
|
|
6
|
+
|
|
7
|
+
if "%~1"=="write_gitignore" goto :write_gitignore
|
|
8
|
+
if "%~1"=="write_readme" goto :write_readme
|
|
9
|
+
if "%~1"=="write_forge" goto :write_forge
|
|
10
|
+
if "%~1"=="write_save" goto :write_save
|
|
11
|
+
if "%~1"=="write_push" goto :write_push
|
|
12
|
+
if "%~1"=="write_snapshots" goto :write_snapshots
|
|
13
|
+
if "%~1"=="write_historial" goto :write_historial
|
|
14
|
+
if "%~1"=="write_abrir" goto :write_abrir
|
|
15
|
+
if "%~1"=="write_auditar" goto :write_auditar
|
|
16
|
+
if "%~1"=="write_serve" goto :write_serve
|
|
17
|
+
goto :eof
|
|
18
|
+
|
|
19
|
+
:write_gitignore
|
|
20
|
+
call :copy_root "gitignore.tpl" ".gitignore"
|
|
21
|
+
goto :eof
|
|
22
|
+
|
|
23
|
+
:write_readme
|
|
24
|
+
call :apply_root "readme.md.tpl" "README.md"
|
|
25
|
+
goto :eof
|
|
26
|
+
|
|
27
|
+
:write_forge
|
|
28
|
+
call :copy_root "forge.cmd.tpl" "forge.cmd"
|
|
29
|
+
goto :eof
|
|
30
|
+
|
|
31
|
+
:write_save
|
|
32
|
+
call :copy_cmd "save.cmd.tpl" "save.cmd"
|
|
33
|
+
goto :eof
|
|
34
|
+
|
|
35
|
+
:write_push
|
|
36
|
+
call :copy_cmd "push.cmd.tpl" "push.cmd"
|
|
37
|
+
goto :eof
|
|
38
|
+
|
|
39
|
+
:write_snapshots
|
|
40
|
+
call :copy_cmd "snapshots.cmd.tpl" "snapshots.cmd"
|
|
41
|
+
goto :eof
|
|
42
|
+
|
|
43
|
+
:write_historial
|
|
44
|
+
call :copy_cmd "historial.cmd.tpl" "historial.cmd"
|
|
45
|
+
goto :eof
|
|
46
|
+
|
|
47
|
+
:write_abrir
|
|
48
|
+
call :copy_cmd "abrir.cmd.tpl" "abrir.cmd"
|
|
49
|
+
goto :eof
|
|
50
|
+
|
|
51
|
+
:write_auditar
|
|
52
|
+
call :copy_cmd "auditar.cmd.tpl" "auditar.cmd"
|
|
53
|
+
goto :eof
|
|
54
|
+
|
|
55
|
+
:write_serve
|
|
56
|
+
call :copy_cmd "serve.cmd.tpl" "serve.cmd"
|
|
57
|
+
call :copy_forge_root "serve-static.js" "serve-static.js"
|
|
58
|
+
goto :eof
|
|
59
|
+
|
|
60
|
+
:copy_root
|
|
61
|
+
set "SRC=%~dp0..\templates\%~1"
|
|
62
|
+
set "DST=%~dp0..\..\%~2"
|
|
63
|
+
if not exist "%SRC%" (
|
|
64
|
+
echo [X] Template no encontrado: %SRC%
|
|
65
|
+
exit /b 1
|
|
66
|
+
)
|
|
67
|
+
copy /Y "%SRC%" "%DST%" >nul
|
|
68
|
+
exit /b 0
|
|
69
|
+
|
|
70
|
+
:copy_cmd
|
|
71
|
+
set "SRC=%~dp0..\templates\%~1"
|
|
72
|
+
set "DST=%~dp0..\commands\%~2"
|
|
73
|
+
if not exist "%SRC%" (
|
|
74
|
+
echo [X] Template no encontrado: %SRC%
|
|
75
|
+
exit /b 1
|
|
76
|
+
)
|
|
77
|
+
copy /Y "%SRC%" "%DST%" >nul
|
|
78
|
+
exit /b 0
|
|
79
|
+
|
|
80
|
+
:copy_forge_root
|
|
81
|
+
set "SRC=%~dp0..\templates\%~1"
|
|
82
|
+
set "DST=%~dp0..\%~2"
|
|
83
|
+
if not exist "%SRC%" (
|
|
84
|
+
echo [X] Template no encontrado: %SRC%
|
|
85
|
+
exit /b 1
|
|
86
|
+
)
|
|
87
|
+
copy /Y "%SRC%" "%DST%" >nul
|
|
88
|
+
exit /b 0
|
|
89
|
+
|
|
90
|
+
:apply_root
|
|
91
|
+
set "SRC=%~dp0..\templates\%~1"
|
|
92
|
+
set "DST=%~dp0..\..\%~2"
|
|
93
|
+
if not exist "%SRC%" (
|
|
94
|
+
echo [X] Template no encontrado: %SRC%
|
|
95
|
+
exit /b 1
|
|
96
|
+
)
|
|
97
|
+
powershell -NoProfile -ExecutionPolicy Bypass -Command "$c = Get-Content -Raw -LiteralPath '%SRC%'; $c = $c.Replace('{{PROJECT_NAME}}', '%PROJECT_NAME%'); $c = $c.Replace('{{FG_VERSION}}', '%FG_VERSION%'); [System.IO.File]::WriteAllText('%DST%', $c, [System.Text.UTF8Encoding]::new($false))"
|
|
98
|
+
exit /b 0
|
package/lib/ui.cmd
CHANGED
|
@@ -1,58 +1,59 @@
|
|
|
1
|
-
@echo off
|
|
2
|
-
REM ============================================================
|
|
3
|
-
REM forge-git / lib/ui.cmd
|
|
4
|
-
REM UI helpers
|
|
5
|
-
REM ============================================================
|
|
6
|
-
|
|
7
|
-
if "%~1"=="banner" goto :banner
|
|
8
|
-
if "%~1"=="step" goto :step
|
|
9
|
-
if "%~1"=="done" goto :done
|
|
10
|
-
if "%~1"=="abort" goto :abort
|
|
11
|
-
goto :eof
|
|
12
|
-
|
|
13
|
-
:banner
|
|
14
|
-
echo.
|
|
15
|
-
echo ############################################
|
|
16
|
-
echo # forge-git v%FG_VERSION% #
|
|
17
|
-
echo # Bootstrap universal de proyecto #
|
|
18
|
-
echo ############################################
|
|
19
|
-
echo.
|
|
20
|
-
echo Proyecto: %PROJECT_NAME%
|
|
21
|
-
echo Ruta: %CD%
|
|
22
|
-
echo.
|
|
23
|
-
goto :eof
|
|
24
|
-
|
|
25
|
-
:step
|
|
26
|
-
echo [%~2] %~3 %~4
|
|
27
|
-
goto :eof
|
|
28
|
-
|
|
29
|
-
:done
|
|
30
|
-
echo.
|
|
31
|
-
echo ############################################
|
|
32
|
-
echo # Bootstrap completado #
|
|
33
|
-
echo ############################################
|
|
34
|
-
echo.
|
|
35
|
-
echo Comandos disponibles:
|
|
36
|
-
echo.
|
|
37
|
-
echo Esenciales:
|
|
38
|
-
echo init.cmd Bootstrap
|
|
39
|
-
echo forge.cmd Menu interactivo
|
|
40
|
-
echo.
|
|
41
|
-
echo Uso CLI directo:
|
|
42
|
-
echo forge save Commit de cambios
|
|
43
|
-
echo forge push Push a GitHub
|
|
44
|
-
echo forge log Ver commits
|
|
45
|
-
echo.
|
|
46
|
-
echo Otros:
|
|
47
|
-
echo forge snap Snapshots
|
|
48
|
-
echo forge audit Reporte diff
|
|
49
|
-
echo forge open Abrir en VS Code
|
|
50
|
-
echo forge
|
|
51
|
-
echo
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
echo
|
|
57
|
-
|
|
1
|
+
@echo off
|
|
2
|
+
REM ============================================================
|
|
3
|
+
REM forge-git / lib/ui.cmd
|
|
4
|
+
REM UI helpers
|
|
5
|
+
REM ============================================================
|
|
6
|
+
|
|
7
|
+
if "%~1"=="banner" goto :banner
|
|
8
|
+
if "%~1"=="step" goto :step
|
|
9
|
+
if "%~1"=="done" goto :done
|
|
10
|
+
if "%~1"=="abort" goto :abort
|
|
11
|
+
goto :eof
|
|
12
|
+
|
|
13
|
+
:banner
|
|
14
|
+
echo.
|
|
15
|
+
echo ############################################
|
|
16
|
+
echo # forge-git v%FG_VERSION% #
|
|
17
|
+
echo # Bootstrap universal de proyecto #
|
|
18
|
+
echo ############################################
|
|
19
|
+
echo.
|
|
20
|
+
echo Proyecto: %PROJECT_NAME%
|
|
21
|
+
echo Ruta: %CD%
|
|
22
|
+
echo.
|
|
23
|
+
goto :eof
|
|
24
|
+
|
|
25
|
+
:step
|
|
26
|
+
echo [%~2] %~3 %~4
|
|
27
|
+
goto :eof
|
|
28
|
+
|
|
29
|
+
:done
|
|
30
|
+
echo.
|
|
31
|
+
echo ############################################
|
|
32
|
+
echo # Bootstrap completado #
|
|
33
|
+
echo ############################################
|
|
34
|
+
echo.
|
|
35
|
+
echo Comandos disponibles:
|
|
36
|
+
echo.
|
|
37
|
+
echo Esenciales:
|
|
38
|
+
echo init.cmd Bootstrap
|
|
39
|
+
echo forge.cmd Menu interactivo
|
|
40
|
+
echo.
|
|
41
|
+
echo Uso CLI directo:
|
|
42
|
+
echo forge save Commit de cambios
|
|
43
|
+
echo forge push Push a GitHub
|
|
44
|
+
echo forge log Ver commits
|
|
45
|
+
echo.
|
|
46
|
+
echo Otros:
|
|
47
|
+
echo forge snap Snapshots
|
|
48
|
+
echo forge audit Reporte diff
|
|
49
|
+
echo forge open Abrir en VS Code
|
|
50
|
+
echo forge serve Servidor de desarrollo
|
|
51
|
+
echo forge help Ayuda completa
|
|
52
|
+
echo.
|
|
53
|
+
goto :eof
|
|
54
|
+
|
|
55
|
+
:abort
|
|
56
|
+
echo.
|
|
57
|
+
echo Bootstrap abortado. Instala los requisitos y vuelve a intentar.
|
|
58
|
+
pause
|
|
58
59
|
goto :eof
|
package/package.json
CHANGED
|
@@ -1,36 +1,38 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "forgegit",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Universal Git bootstrap kit for Windows",
|
|
5
|
-
"bin": {
|
|
6
|
-
"forge": "./tools/bin/forge.cmd"
|
|
7
|
-
},
|
|
8
|
-
"files": [
|
|
9
|
-
"init.cmd",
|
|
10
|
-
"config.cmd",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"tools/
|
|
19
|
-
"tools/
|
|
20
|
-
"tools/
|
|
21
|
-
"tools/
|
|
22
|
-
"tools/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "forgegit",
|
|
3
|
+
"version": "1.4.1",
|
|
4
|
+
"description": "Universal Git bootstrap kit for Windows",
|
|
5
|
+
"bin": {
|
|
6
|
+
"forge": "./tools/bin/forge.cmd"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"init.cmd",
|
|
10
|
+
"config.cmd",
|
|
11
|
+
"forge.cmd",
|
|
12
|
+
"MANUAL.md",
|
|
13
|
+
"README.md",
|
|
14
|
+
".forge/",
|
|
15
|
+
"lib/",
|
|
16
|
+
"templates/",
|
|
17
|
+
"tests/test.cmd",
|
|
18
|
+
"tools/install.cmd",
|
|
19
|
+
"tools/uninstall.cmd",
|
|
20
|
+
"tools/restore.cmd",
|
|
21
|
+
"tools/pack.cmd",
|
|
22
|
+
"tools/release.cmd",
|
|
23
|
+
"tools/bin/forge.cmd",
|
|
24
|
+
"tools/bin/forge-update.cmd"
|
|
25
|
+
],
|
|
26
|
+
"keywords": [
|
|
27
|
+
"git",
|
|
28
|
+
"bootstrap",
|
|
29
|
+
"windows",
|
|
30
|
+
"cli"
|
|
31
|
+
],
|
|
32
|
+
"author": "vloitz",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/vloitz/forgeGit"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/templates/forge.cmd.tpl
CHANGED
|
@@ -28,7 +28,7 @@ if not exist "%CMD_DIR%\save.cmd" (
|
|
|
28
28
|
exit /b 1
|
|
29
29
|
)
|
|
30
30
|
|
|
31
|
-
REM --- Modo CLI directo
|
|
31
|
+
REM --- Modo CLI directo ---
|
|
32
32
|
if not "%~1"=="" (
|
|
33
33
|
if /i "%~1"=="save" ( call "%CMD_DIR%\save.cmd" & exit /b 0 )
|
|
34
34
|
if /i "%~1"=="push" ( call "%CMD_DIR%\push.cmd" & exit /b 0 )
|
|
@@ -36,6 +36,7 @@ if not "%~1"=="" (
|
|
|
36
36
|
if /i "%~1"=="log" ( call "%CMD_DIR%\historial.cmd" & exit /b 0 )
|
|
37
37
|
if /i "%~1"=="audit" ( call "%CMD_DIR%\auditar.cmd" & exit /b 0 )
|
|
38
38
|
if /i "%~1"=="open" ( call "%CMD_DIR%\abrir.cmd" & exit /b 0 )
|
|
39
|
+
if /i "%~1"=="serve" ( call "%CMD_DIR%\serve.cmd" & exit /b 0 )
|
|
39
40
|
if /i "%~1"=="help" goto :help
|
|
40
41
|
if /i "%~1"=="-h" goto :help
|
|
41
42
|
if /i "%~1"=="--help" goto :help
|
|
@@ -45,7 +46,7 @@ if not "%~1"=="" (
|
|
|
45
46
|
)
|
|
46
47
|
|
|
47
48
|
REM ============================================================
|
|
48
|
-
REM MENU PRINCIPAL
|
|
49
|
+
REM MENU PRINCIPAL
|
|
49
50
|
REM ============================================================
|
|
50
51
|
:menu
|
|
51
52
|
cls
|
|
@@ -63,6 +64,7 @@ echo !C_BC!Herramientas:!C_RS!
|
|
|
63
64
|
echo !C_YE![4]!C_RS! Snapshots !C_GY!(backup/restore)!C_RS!
|
|
64
65
|
echo !C_YE![5]!C_RS! Auditar cambios !C_GY!(diff report)!C_RS!
|
|
65
66
|
echo !C_YE![6]!C_RS! Abrir en VS Code
|
|
67
|
+
echo !C_YE![7]!C_RS! Servidor dev !C_GY!(auto-detect)!C_RS!
|
|
66
68
|
echo.
|
|
67
69
|
echo !C_BC!Sistema:!C_RS!
|
|
68
70
|
echo !C_YE![0]!C_RS! Salir
|
|
@@ -79,6 +81,7 @@ if "!OPT!"=="3" ( call "%CMD_DIR%\historial.cmd" & echo. & pause & goto :menu )
|
|
|
79
81
|
if "!OPT!"=="4" ( call "%CMD_DIR%\snapshots.cmd" & echo. & pause & goto :menu )
|
|
80
82
|
if "!OPT!"=="5" ( call "%CMD_DIR%\auditar.cmd" & echo. & pause & goto :menu )
|
|
81
83
|
if "!OPT!"=="6" ( call "%CMD_DIR%\abrir.cmd" & echo. & pause & goto :menu )
|
|
84
|
+
if "!OPT!"=="7" ( call "%CMD_DIR%\serve.cmd" & echo. & pause & goto :menu )
|
|
82
85
|
if "!OPT!"=="0" goto :end
|
|
83
86
|
if /i "!OPT!"=="q" goto :end
|
|
84
87
|
|
|
@@ -101,6 +104,7 @@ echo !C_WH!forge snap!C_RS! Snapshots
|
|
|
101
104
|
echo !C_WH!forge log!C_RS! Historial
|
|
102
105
|
echo !C_WH!forge audit!C_RS! Auditar cambios
|
|
103
106
|
echo !C_WH!forge open!C_RS! Abrir en VS Code
|
|
107
|
+
echo !C_WH!forge serve!C_RS! Servidor de desarrollo
|
|
104
108
|
echo !C_WH!forge help!C_RS! Esta ayuda
|
|
105
109
|
echo.
|
|
106
110
|
goto :end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// serve-static.js - Minimal static file server (no dependencies)
|
|
2
|
+
// Usage: node serve-static.js [port] [root]
|
|
3
|
+
|
|
4
|
+
const http = require('http');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
const PORT = parseInt(process.argv[2] || '8080', 10);
|
|
9
|
+
const ROOT = path.resolve(process.argv[3] || process.cwd());
|
|
10
|
+
|
|
11
|
+
const MIME = {
|
|
12
|
+
'.html': 'text/html; charset=utf-8',
|
|
13
|
+
'.htm': 'text/html; charset=utf-8',
|
|
14
|
+
'.js': 'application/javascript; charset=utf-8',
|
|
15
|
+
'.mjs': 'application/javascript; charset=utf-8',
|
|
16
|
+
'.css': 'text/css; charset=utf-8',
|
|
17
|
+
'.json': 'application/json; charset=utf-8',
|
|
18
|
+
'.xml': 'application/xml; charset=utf-8',
|
|
19
|
+
'.txt': 'text/plain; charset=utf-8',
|
|
20
|
+
'.md': 'text/markdown; charset=utf-8',
|
|
21
|
+
'.png': 'image/png',
|
|
22
|
+
'.jpg': 'image/jpeg',
|
|
23
|
+
'.jpeg': 'image/jpeg',
|
|
24
|
+
'.gif': 'image/gif',
|
|
25
|
+
'.svg': 'image/svg+xml',
|
|
26
|
+
'.webp': 'image/webp',
|
|
27
|
+
'.ico': 'image/x-icon',
|
|
28
|
+
'.wasm': 'application/wasm',
|
|
29
|
+
'.woff': 'font/woff',
|
|
30
|
+
'.woff2': 'font/woff2',
|
|
31
|
+
'.ttf': 'font/ttf',
|
|
32
|
+
'.mp4': 'video/mp4',
|
|
33
|
+
'.webm': 'video/webm',
|
|
34
|
+
'.mp3': 'audio/mpeg',
|
|
35
|
+
'.wav': 'audio/wav'
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const server = http.createServer((req, res) => {
|
|
39
|
+
let urlPath;
|
|
40
|
+
try {
|
|
41
|
+
urlPath = decodeURIComponent(req.url.split('?')[0]);
|
|
42
|
+
} catch (e) {
|
|
43
|
+
res.writeHead(400); res.end('400 Bad Request'); return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (urlPath === '/') urlPath = '/index.html';
|
|
47
|
+
|
|
48
|
+
const filePath = path.resolve(path.join(ROOT, urlPath));
|
|
49
|
+
|
|
50
|
+
// Bloqueo de path traversal
|
|
51
|
+
if (!filePath.startsWith(ROOT)) {
|
|
52
|
+
res.writeHead(403); res.end('403 Forbidden'); return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
fs.readFile(filePath, (err, data) => {
|
|
56
|
+
if (err) {
|
|
57
|
+
res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
58
|
+
res.end('404 Not Found: ' + urlPath);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
62
|
+
res.writeHead(200, {
|
|
63
|
+
'Content-Type': MIME[ext] || 'application/octet-stream',
|
|
64
|
+
'Cache-Control': 'no-cache'
|
|
65
|
+
});
|
|
66
|
+
res.end(data);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
server.on('error', (err) => {
|
|
71
|
+
if (err.code === 'EADDRINUSE') {
|
|
72
|
+
console.error('[ERROR] Port ' + PORT + ' is already in use.');
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
console.error('[ERROR] ' + err.message);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
server.listen(PORT, '127.0.0.1', () => {
|
|
80
|
+
console.log('');
|
|
81
|
+
console.log(' Serving ' + ROOT);
|
|
82
|
+
console.log(' -> http://localhost:' + PORT + '/');
|
|
83
|
+
console.log('');
|
|
84
|
+
console.log(' Press Ctrl+C to stop');
|
|
85
|
+
console.log('');
|
|
86
|
+
});
|