node.jsとOpenWeatherMap APIを使って天気予報サイトを作成してます。
jsの中でAPIキーを隠す方法が無いらしくnode.js内でAPIを呼び出してます。
jsでgetして、node.jsでAPIを呼びだしています。
そうするとjs内のurlを使って http://localhost:3000/get
みたいに他の人が利用されるのではないのか?
他の人に利用されないようにするにはどうすればいいのでしょうか?
また、他の安全なAPIの呼び出し方があったら教えてほしいです。
よろしくお願いします。
jsのコード
fetch("get")
.then((response) => {
if (!response.ok) {
throw new Error();
}
console.log(response);
return response.json(); // あるいは response.json()
})
.then((json) => {
console.log("?? ~ file: App.vue ~ line 32 ~ .then ~ json", json);
})
.catch((reason) => {
console.error(reason);
});
node.jsのコード
app.get("/get", function (req, res) {
//ここでapiを呼び出して結果を返す
});