Skip to content

Commit d6c885f

Browse files
committed
server-ssl.js
create production/staging folders in ssl folder ssl/production for production certificates/keys ssl/staging for staging certificates/keys the production certificate doesn't get deleted every time you use `--staging` combines with the previous commit to make sure the ARI always works updated the layout diagram /root │ ├── /error │ ├── 404.html │ └── 500.html │ ├── /ssl │ ├── /openssl │ ├── /production │ │ │ │ │ ├── ... │ │ ├── private-key.pem │ │ └── certificate.pem │ │ │ ├── /staging │ │ │ │ │ ├── ... │ │ ├── private-key.pem │ │ └── certificate.pem │ │ │ └── state.js │ ├── /wwwroot │ └── index.html <---- Your website goes here │ ├── server-ssl.js <--- server config └── start-windows.bat
1 parent ee904aa commit d6c885f

4 files changed

Lines changed: 37 additions & 12 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
node.exe
1+
ssl/staging/
2+
ssl/production/
23
ssl/private-key.pem
34
ssl/certificate.pem
45
ssl/acmePublicSignKey.raw
@@ -8,3 +9,4 @@ ssl/acmePrivateKey.raw
89
ssl/last_update.ez
910
ssl/last_certification.ez
1011
node_modules/
12+
node.exe

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,18 @@ This layout keeps the project organized and maintainable, separating error handl
115115
116116
├── /ssl
117117
│ ├── /openssl
118+
│ ├── /production
119+
│ │ │
120+
│ │ ├── ...
121+
│ │ ├── private-key.pem
122+
│ │ └── certificate.pem
123+
│ │
124+
│ ├── /staging
125+
│ │ │
126+
│ │ ├── ...
127+
│ │ ├── private-key.pem
128+
│ │ └── certificate.pem
118129
│ │
119-
│ ├── private-key.pem
120-
│ └── certificate.pem
121130
│ └── state.js
122131
123132
├── /wwwroot

ssl/state.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export const STATE = {
120120

121121
STATE.expireDate && STATE.timeUntilRenew(STATE.expireDate);
122122

123-
const SSL = join(__rootDir, STATE.SSL);
123+
const SSL = join(__rootDir, STATE.SSL, STATE.optStaging ? "staging" : "production");
124124
const PK = join(SSL, STATE.optPk);
125125
const CERT = join(SSL, STATE.optCert);
126126

start-windows.bat

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ set "KEYS=0"
1515
set "SKIPNODE=0"
1616
set "OPEN_SSL="
1717
set "OPEN_SSL_IN_PATH=0"
18+
set "STAGING=0"
19+
set "PATH1=production"
1820

1921
title Starting SSL Web Server
2022

@@ -32,6 +34,9 @@ if "%~1"=="--port" (
3234
) else if "%~1"=="--skipNodeUpdate" (
3335
set "SKIPNODE=1"
3436
shift
37+
) else if "%~1"=="--staging" (
38+
set "STAGING=1"
39+
shift
3540
)
3641

3742
shift
@@ -40,6 +45,15 @@ goto loop
4045

4146
if NOT "%PORT%"=="" ( echo Port: %PORT% )
4247

48+
IF "%STAGING%"=="1" (
49+
set "PATH1=staging"
50+
echo !PATH1!
51+
)
52+
53+
if NOT EXIST "%currentPath%/ssl/%PATH1%" (
54+
mkdir "%currentPath%/ssl/%PATH1%"
55+
)
56+
4357
@REM check if openssl is in the ssl folder
4458
@REM prefers openssl from the ssl folder
4559
IF "%OPEN_SSL_IN_PATH%"=="0" (
@@ -88,28 +102,28 @@ IF "!OPEN_SSL_IN_PATH!"=="0" (
88102

89103
if "%CERT%"=="" (
90104
set "CERT=certificate.pem"
91-
if NOT EXIST "%currentPath%/ssl/%CERT%" ( set "KEYS=1" )
105+
if NOT EXIST "%currentPath%/ssl/%PATH1%/!CERT!" ( set "KEYS=1" )
92106
)
93107

94108
if "%PK%"=="" (
95109
set "PK=private-key.pem"
96-
if NOT EXIST "%currentPath%/ssl/%PK%" ( set "KEYS=1" )
110+
if NOT EXIST "%currentPath%/ssl/%PATH1%/!PK!" ( set "KEYS=1" )
97111
)
98112

99113
if "%KEYS%"=="1" (
100114
echo --------
101115
echo Generating Keys for Local Development
102116

103117
if "!OPEN_SSL_IN_PATH!"=="1" (
104-
openssl req -x509 -newkey rsa:2048 -nodes -sha256 -keyout "ssl/%PK%" -out "ssl/%CERT%" -days 365 -subj "/CN=localhost"
118+
openssl req -x509 -newkey rsa:2048 -nodes -sha256 -keyout "ssl/%PATH1%/%PK%" -out "ssl/%PATH1%/%CERT%" -days 365 -subj "/CN=localhost"
105119
)
106120

107121
if "!OPEN_SSL_IN_PATH!"=="2" (
108-
%currentPath%/ssl/openssl/bin/openssl.exe req -x509 -newkey rsa:2048 -nodes -sha256 -keyout "ssl/%PK%" -out "ssl/%CERT%" -days 365 -subj "/CN=localhost"
122+
%currentPath%/ssl/openssl/bin/openssl.exe req -x509 -newkey rsa:2048 -nodes -sha256 -keyout "ssl/%PATH1%/%PK%" -out "ssl/%PATH1%/%CERT%" -days 365 -subj "/CN=localhost"
109123
)
110124

111-
if EXIST "%currentPath%/ssl/%PK%" ( echo Successfully Generated Private Key )
112-
if EXIST "%currentPath%/ssl/%CERT%" ( echo Successfully Generated Certificate ) else (
125+
if EXIST "%currentPath%/ssl/%PATH1%/%PK%" ( echo Successfully Generated Private Key )
126+
if EXIST "%currentPath%/ssl/%PATH1%/%CERT%" ( echo Successfully Generated Certificate ) else (
113127
echo Certificate Needed to continue Install OpenSSL and try again
114128
exit
115129
)
@@ -139,13 +153,13 @@ setlocal
139153
@REM Check Certificate end date
140154

141155
if "!OPEN_SSL_IN_PATH!"=="1" (
142-
for /f "tokens=2 delims==" %%a in ('openssl x509 -in "%currentPath%/ssl/%CERT%" -enddate -noout') do (
156+
for /f "tokens=2 delims==" %%a in ('openssl x509 -in "%currentPath%/ssl/%PATH1%/%CERT%" -enddate -noout') do (
143157
set "DATE=%%a"
144158
)
145159
)
146160

147161
if "!OPEN_SSL_IN_PATH!"=="2" (
148-
for /f "tokens=2 delims==" %%a in ('%currentPath%/ssl/openssl/bin/openssl.exe x509 -in "%currentPath%/ssl/%CERT%" -enddate -noout') do (
162+
for /f "tokens=2 delims==" %%a in ('%currentPath%/ssl/openssl/bin/openssl.exe x509 -in "%currentPath%/ssl/%PATH1%/%CERT%" -enddate -noout') do (
149163
set "DATE=%%a"
150164
)
151165
)

0 commit comments

Comments
 (0)