1
Fork 0

Add a meaningful User-Agent to API calls.

This commit is contained in:
Bauke 2022-01-04 00:17:05 +01:00
parent f28ef60faf
commit 0a43505bdc
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
4 changed files with 7 additions and 1 deletions

View File

@ -5,4 +5,5 @@ declare global {
// These are created in `vite.config.ts` and inserted by Vite at build time.
const blinkCommitHash: string;
const blinkVersion: string;
const blinkUserAgent: string;
}

View File

@ -32,6 +32,7 @@ export default class Release {
const apiResponse = await window.fetch(this.apiUrl(mbid), {
headers: {
accept: 'application/json',
'user-agent': blinkUserAgent,
},
});

View File

@ -25,6 +25,7 @@ export default async function searchReleases(
const response = await window.fetch(url, {
headers: {
accept: 'application/json',
'user-agent': blinkUserAgent,
},
});

View File

@ -23,14 +23,17 @@ function gitRevParse(): string {
return JSON.stringify(revParse.stdout.trim());
}
const blinkVersion = process.env.npm_package_version ?? '<unknown version>';
export default defineConfig({
build: {
outDir: buildDir,
sourcemap: true,
},
define: {
blinkVersion: JSON.stringify(process.env.npm_package_version),
blinkVersion: JSON.stringify(blinkVersion),
blinkCommitHash: gitRevParse(),
blinkUserAgent: `"Blink/${blinkVersion} (https://github.com/Bauke/blink)"`,
},
publicDir: path.join(sourceDir, 'assets'),
root: sourceDir,