Refactor WEBMENTION_TOKEN handling: read from file and remove environment configuration
All checks were successful
Deploy / deploy (push) Successful in 1m17s
All checks were successful
Deploy / deploy (push) Successful in 1m17s
This commit is contained in:
parent
131c0e90bb
commit
553cc63023
3 changed files with 19 additions and 15 deletions
|
|
@ -1,8 +1,24 @@
|
|||
---
|
||||
import { WEBMENTION_TOKEN } from 'astro:env/server';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { DEFAULT_LOCALE, type Locale } from '~/consts';
|
||||
import { getLocaleFromUrl, t } from '~/i18n/ui';
|
||||
|
||||
function readTokenFromFile(): string | undefined {
|
||||
const paths = ['/app/.webmention-token', '.webmention-token'];
|
||||
for (const p of paths) {
|
||||
try {
|
||||
const raw = readFileSync(p, 'utf-8').trim();
|
||||
if (raw) return raw;
|
||||
} catch {
|
||||
// file not present, try next
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const FILE_TOKEN = readTokenFromFile();
|
||||
const WEBMENTION_TOKEN = FILE_TOKEN ?? (import.meta.env as Record<string, string | undefined>).WEBMENTION_TOKEN;
|
||||
|
||||
interface WMAuthor {
|
||||
name?: string;
|
||||
url?: string;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue