webサーバを立ち上げてchromeにアドレスを入れると「favicon」を要求されるけどローカルファイルが存在しなくてエラー発生し、サーバが落ちる、という感じになってしまう。
だから、ローカルファイルの有無を確認するためのソースが以下。
だから、ローカルファイルの有無を確認するためのソースが以下。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --allow-read | |
async function exists(filePath: string): Promise<boolean> { | |
try { | |
await Deno.lstat(filePath); | |
return true; | |
} catch (err) { | |
if (err instanceof Deno.errors.NotFound) { | |
return false; | |
} | |
throw err; | |
} | |
} | |
async function test(path:string){ | |
const res = await exists(path) | |
console.log(path + ' : ' + res) | |
} | |
test('c:/deno/1.10.1/webServer.ts') | |
test('c:/deno/1.10.1/webServer.ta') |
実行結果
こんな基礎的な事に手こずると思っていなかったのですが、予想外に時間がかかりました。
ネット上にいくつもあるサンプルが何故か私の環境ではエラーになってしまうのはバージョンの問題?
下記のページを参考にさせて頂きました。
std@0.97.0 | Deno
ファイルの存在確認をする
こんな基礎的な事に手こずると思っていなかったのですが、予想外に時間がかかりました。
ネット上にいくつもあるサンプルが何故か私の環境ではエラーになってしまうのはバージョンの問題?
下記のページを参考にさせて頂きました。
std@0.97.0 | Deno
ファイルの存在確認をする
0 件のコメント:
コメントを投稿