# Local CA {%hackmd @RintarouTW/About %} ## Install ```!bash brew install mkcert ``` **Installed CA path** ```!bash mkcert -CAROOT ~/Library/Application Support/mkcert ``` ## Make Server Certificate for localhost ```!bash mkcert localhost ``` ### express with server certificate ```!javascript import https from 'https' import express from 'express' const credentials = { cert: fs.readFileSync("/Users/allen/.localhost-ssl/localhost.pem"), key: fs.readFileSync("/Users/allen/.localhost-ssl/localhost-key.pem") } const app = express() const server = https.createServer(credentials, app) ``` ## Make Client Certificate ```!bash mkcert -client localhost ``` ### Let Node to know local CA certificate ```!bash export NODE_EXTRA_CA_CERTS=~/Library/Applcation Support/mkcert/rootCA.pem ``` **axios to use certificate** ```!javascript const httpsAgent = new https.Agent({ //rejectUnauthorized: false, // (NOTE: this will disable client verification) cert: fs.readFileSync("./localhost-client.pem"), key: fs.readFileSync("./localhost-client-key.pem"), passphrase: "YYY" }) axios.get('https://localhost/',httpsAgent).then(...) ``` ###### tags: `localhost` `CA` `https` `certificate` `axios` `express`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up