Skip to content

Commit

Permalink
Check if token file env var is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Radiokot committed Dec 2, 2023
1 parent 5ad420d commit 11e4eed
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/routes/api/settings/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ async function getTokenFromFile(): Promise<string | null> {
let tokenFileHandle
try {
try {
await fsPromises.access(env.CLOUDFLARED_TOKEN_FILE, fsConstants.R_OK)
} catch {
await fsPromises.access(env.CLOUDFLARED_TOKEN_FILE!, fsConstants.R_OK)
} catch(err) {
console.warn('settings.getTokenFromFile: file_not_accessible:', {
message: (err as Error).message,
file: env.CLOUDFLARED_TOKEN_FILE
})

return null
}

tokenFileHandle = await fsPromises.open(env.CLOUDFLARED_TOKEN_FILE, 'r')
tokenFileHandle = await fsPromises.open(env.CLOUDFLARED_TOKEN_FILE!, 'r')
return (await tokenFileHandle.readFile(TOKEN_FILE_ENCODING)).trim()
} finally {
if (tokenFileHandle !== undefined) {
Expand All @@ -58,7 +59,7 @@ async function getTokenFromFile(): Promise<string | null> {
async function saveTokenToFile(token: string) {
let tokenFileHandle
try {
tokenFileHandle = await fsPromises.open(env.CLOUDFLARED_TOKEN_FILE, 'w')
tokenFileHandle = await fsPromises.open(env.CLOUDFLARED_TOKEN_FILE!, 'w')
await tokenFileHandle.writeFile(token, {
encoding: TOKEN_FILE_ENCODING,
flag: 'w'
Expand Down

0 comments on commit 11e4eed

Please sign in to comment.