Skip to content

Commit

Permalink
[#549] 'unable to verify first certificate' 에러 해결 (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
gxxrxn committed Jun 17, 2024
1 parent 1d56794 commit bdfa458
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"dev": "next dev -H local.dev.dadok.app",
"ssl-dev": "node scripts/server.js local.dev.dadok.app",
"dev-ssl": "node scripts/server.js local.dev.dadok.app",
"build": "next build",
"start": "next start -H local.dev.dadok.app",
"lint": "next lint",
Expand Down
7 changes: 6 additions & 1 deletion scripts/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const fs = require('fs');
const https = require('https');
const { parse } = require('url');
const { execSync } = require('child_process');
const next = require('next');

const dev = process.env.NODE_ENV !== 'production';
Expand All @@ -13,6 +14,7 @@ const app = next({ dev, hostname, port });
const handle = app.getRequestHandler();

const SELF_CERTIFICATES_PATH = {
ca: `${execSync('mkcert -CAROOT').toString().replace(/\s/g, '')}/rootCA.pem`,
key: './.certificates/localhost-key.pem',
cert: './.certificates/localhost.pem',
};
Expand All @@ -22,6 +24,9 @@ const option = {
cert: fs.readFileSync(SELF_CERTIFICATES_PATH.cert),
};

// To resolve the 'unable to verify first certificate' error
process.env.NODE_EXTRA_CA_CERTS = SELF_CERTIFICATES_PATH.ca;

app.prepare().then(() => {
https
.createServer(option, async (req, res) => {
Expand All @@ -38,6 +43,6 @@ app.prepare().then(() => {
})
.listen(port, error => {
if (error) throw error;
console.log(`> Ready on https://${hostname}:${port}`);
console.log('\x1b[32m%s', `> ready on https://${hostname}:${port}\n`);
});
});

0 comments on commit bdfa458

Please sign in to comment.