0

i applied to use a dictionary API and it was asked the URL which i would be using it, i choosed locahost:19006, because it's where the local server is opening. And i have the API key, but for some reason i'm having CORS issue. So i'm trying to fetch it through a proxy server, but i'm receiving this error:

Error: AxiosError: unable to verify the first certificate
    at TLSSocket.onConnectSecure (node:_tls_wrap:1530:34)
    at TLSSocket.emit (node:events:390:28)
    at TLSSocket._finishInit (node:_tls_wrap:944:8)
    at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:725:12) {
  code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'

This is the proxyServer.js:

const app = express();
app.use(cors());

const https = require("https");
const agent = new https.Agent({
  rejectUnauthorized: false,
});

app.get("/words", async (req, res) => {
  await axios
    .get(
      `https://krdict.korean.go.kr/api/search?certkey_no=4013&key=${API_KEY}&type_search=search&part=word&q=%EB%82%98%EB%AC%B4&sort=dict`,
      { agent }
    )
    .then((response) => {
      console.log("Response:", response.data);
    })
    .catch((error) => console.log("Error:", error));
});

app.listen(3000, () => console.log("listening on port 3000"));

Does anyone know how to solve it?

José Carlos
  • 626
  • 3
  • 23
  • Seems like a duplicate of https://stackoverflow.com/questions/20082893/unable-to-verify-leaf-signature https://stackoverflow.com/questions/31673587/error-unable-to-verify-the-first-certificate-in-nodejs?noredirect=1&lq=1 (the second one solved my problem) – Munchkin Sep 15 '22 at 13:09

1 Answers1

-1
import axios from 'axios'
import https from 'https'
import { API_HOST } from './config'

const instance = axios.create({
    baseURL: API_HOST,
})

instance.defaults.httpsAgent = new https.Agent({
    rejectUnauthorized: false,
})

instance.interceptors.request.use(
    (config) => {
        return config
    },
    (error) => {
        return Promise.reject(error)
    }
)

I used this configuration. This solved my problem.