-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-server.bat
More file actions
136 lines (126 loc) · 2.8 KB
/
start-server.bat
File metadata and controls
136 lines (126 loc) · 2.8 KB
1
2
3
4
5
6
7
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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
@echo off
echo ============================================
echo Local Server
echo ============================================
echo.
set PORT=8080
set DIR=%CD%
:parse
if "%~1"=="" goto menu
if "%~1"=="-p" (
for %%a in (%2) do set PORT=%%~a
shift
shift
goto parse
)
if "%~1"=="--port" (
for %%a in (%2) do set PORT=%%~a
shift
shift
goto parse
)
if "%~1"=="-d" (
set DIR=%2
shift
shift
goto parse
)
if "%~1"=="--dir" (
set DIR=%2
shift
shift
goto parse
)
set DIR=%1
shift
goto parse
:menu
echo.
echo [1] Python Server
echo [2] Node.js Server
echo [0] Exit
echo.
set /p choice="Select option: "
if "%choice%"=="1" goto run_python
if "%choice%"=="2" goto run_node
if "%choice%"=="0" exit
goto menu
:run_python
python --version >nul 2>&1
if %errorlevel% equ 0 (
echo [OK] Python found
echo [INFO] Serving: %DIR%
echo [INFO] Port: %PORT%
echo.
echo Starting server...
echo ============================================
echo.
echo Examples:
echo http://localhost:%PORT%
echo http://localhost:%PORT%/admin.html
echo start-server.bat -p 3000 -d "C:\site"
echo start-server.bat -d "C:\site"
echo.
echo ============================================
pushd "%DIR%"
python -m http.server %PORT%
popd
goto :done
)
echo.
echo [WARNING] Python is not installed!
echo.
set /p install="Do you want to install Python now? (Y/N): "
if /i "%install%"=="Y" goto install_python
echo Installation cancelled.
pause
exit /b 1
:install_python
echo.
echo [INFO] Installing Python...
powershell -Command "irm https://www.python.org/ftp/python/3.12.1/python-3.12.1-amd64.exe -OutFile python.exe"
start /wait python.exe /quiet InstallAllUsers=1 PrependPath=1
del python.exe
echo [OK] Python installed!
pause
exit /b 0
:run_node
node --version >nul 2>&1
if %errorlevel% equ 0 (
echo [OK] Node.js found
echo.
if not exist "node_modules" (
echo [INFO] Installing dependencies...
call npm install
echo.
)
echo Starting server...
echo ============================================
echo.
echo Examples:
echo http://localhost:%PORT%
echo http://localhost:%PORT%/admin.html
echo start-server.bat -p 3000 -d "C:\site"
echo.
echo ============================================
node server.js
goto :done
)
echo.
echo [WARNING] Node.js is not installed!
echo.
set /p install="Do you want to install Node.js now? (Y/N): "
if /i "%install%"=="Y" goto install_node
echo Installation cancelled.
pause
exit /b 1
:install_node
echo.
echo [INFO] Installing Node.js...
powershell -Command "irm https://nodejs.org/dist/v20.11.0/node-v20.11.0-x64.msi -OutFile node.msi"
start /wait msiexec /i node.msi /quiet
del node.msi 2>nul
echo [OK] Node.js installed!
pause
exit /b 0
:done