Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
nginx-proxy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
nginx-proxy
Commits
c5af1036
Commit
c5af1036
authored
Apr 18, 2024
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix acme thing
parent
8b60f55e
Pipeline
#26558
passed with stages
in 26 minutes and 53 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
15 deletions
+22
-15
src/acme.ts
src/acme.ts
+22
-15
No files found.
src/acme.ts
View file @
c5af1036
import
{
createServer
,
Server
}
from
'
http
'
;
import
{
createServer
}
from
'
http
'
;
import
acme
,
{
Client
}
from
'
acme-client
'
;
import
acme
,
{
Client
}
from
'
acme-client
'
;
import
fs
from
'
fs
'
;
import
fs
from
'
fs
'
;
import
path
from
'
path
'
;
let
email
:
string
;
let
email
:
string
;
export
const
domainsToBeSigned
:
string
[]
=
[];
export
const
domainsToBeSigned
:
string
[]
=
[];
...
@@ -35,6 +36,9 @@ export async function runSignCert() {
...
@@ -35,6 +36,9 @@ export async function runSignCert() {
// 404
// 404
res
.
writeHead
(
404
);
res
.
writeHead
(
404
);
res
.
end
(
'
Token not Found
'
);
res
.
end
(
'
Token not Found
'
);
console
.
error
(
`
${
req
.
socket
.
remoteAddress
}
: Invalid request for
${
req
.
url
}
`
,
);
return
;
return
;
}
}
const
content
=
contentMap
.
get
(
token
);
const
content
=
contentMap
.
get
(
token
);
...
@@ -42,18 +46,30 @@ export async function runSignCert() {
...
@@ -42,18 +46,30 @@ export async function runSignCert() {
// 404
// 404
res
.
writeHead
(
404
);
res
.
writeHead
(
404
);
res
.
end
(
'
Content not Found
'
);
res
.
end
(
'
Content not Found
'
);
console
.
error
(
`
${
req
.
socket
.
remoteAddress
}
: Token not found for
${
token
}
`
,
);
return
;
return
;
}
}
res
.
writeHead
(
200
);
res
.
writeHead
(
200
);
console
.
error
(
`
${
req
.
socket
.
remoteAddress
}
: Serving token for
${
token
}
:
${
content
}
`
,
);
res
.
end
(
content
);
res
.
end
(
content
);
}).
listen
(
80
);
}).
listen
(
80
);
await
fs
.
promises
.
mkdir
(
'
/etc/nginx/acme
'
,
{
recursive
:
true
});
const
certDir
=
`/etc/nginx/certs/
${
domainsToBeSigned
[
0
]}
`
;
const
accountFile
=
path
.
join
(
certDir
,
'
account.pem
'
);
const
fullchainFile
=
path
.
join
(
certDir
,
'
fullchain.pem
'
);
const
privkeyFile
=
path
.
join
(
certDir
,
'
privkey.pem
'
);
await
fs
.
promises
.
mkdir
(
certDir
,
{
recursive
:
true
,
});
let
accountKey
:
Buffer
;
let
accountKey
:
Buffer
;
try
{
try
{
accountKey
=
await
fs
.
promises
.
readFile
(
'
/etc/nginx/acme/account.pem
'
);
accountKey
=
await
fs
.
promises
.
readFile
(
accountFile
);
}
catch
(
e
)
{
}
catch
(
e
)
{
accountKey
=
await
acme
.
forge
.
createPrivateKey
();
accountKey
=
await
acme
.
forge
.
createPrivateKey
();
await
fs
.
promises
.
writeFile
(
'
/etc/nginx/acme/account.pem
'
,
accountKey
);
await
fs
.
promises
.
writeFile
(
accountFile
,
accountKey
);
}
}
const
acmeClient
=
new
Client
({
const
acmeClient
=
new
Client
({
directoryUrl
:
acme
.
directory
.
letsencrypt
.
production
,
directoryUrl
:
acme
.
directory
.
letsencrypt
.
production
,
...
@@ -82,17 +98,8 @@ export async function runSignCert() {
...
@@ -82,17 +98,8 @@ export async function runSignCert() {
});
});
console
.
error
(
'
Certificate signed
'
);
console
.
error
(
'
Certificate signed
'
);
// save certificate as fullchain.pem and key as privkey.pem
// save certificate as fullchain.pem and key as privkey.pem
await
fs
.
promises
.
mkdir
(
`/etc/nginx/certs/
${
domainsToBeSigned
[
0
]}
`
,
{
await
fs
.
promises
.
writeFile
(
fullchainFile
,
certificate
);
recursive
:
true
,
await
fs
.
promises
.
writeFile
(
privkeyFile
,
certificateKey
);
});
await
fs
.
promises
.
writeFile
(
`/etc/nginx/certs/
${
domainsToBeSigned
[
0
]}
/fullchain.pem`
,
certificate
,
);
await
fs
.
promises
.
writeFile
(
`/etc/nginx/certs/
${
domainsToBeSigned
[
0
]}
/privkey.pem`
,
certificateKey
,
);
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
error
(
console
.
error
(
`Failed to sign certificate for
${
domainsToBeSigned
.
join
(
'
,
'
)}
:
${
`Failed to sign certificate for
${
domainsToBeSigned
.
join
(
'
,
'
)}
:
${
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment