forked from Lissy93/web-check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
astro.config.mjs
79 lines (64 loc) · 2.64 KB
/
astro.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { defineConfig } from 'astro/config';
// Integrations
import svelte from '@astrojs/svelte';
import react from "@astrojs/react";
import partytown from '@astrojs/partytown';
import sitemap from '@astrojs/sitemap';
// Adapters
import vercelAdapter from '@astrojs/vercel/serverless';
import netlifyAdapter from '@astrojs/netlify';
import nodeAdapter from '@astrojs/node';
import cloudflareAdapter from '@astrojs/cloudflare';
// Helper function to unwrap both Vite and Node environment variables
const unwrapEnvVar = (varName, fallbackValue) => {
const classicEnvVar = process?.env && process.env[varName];
const viteEnvVar = import.meta.env[varName];
return classicEnvVar || viteEnvVar || fallbackValue;
}
// Determine the deploy target (vercel, netlify, cloudflare, node)
const deployTarget = unwrapEnvVar('PLATFORM', 'node').toLowerCase();
// Determine the output mode (server, hybrid or static)
const output = unwrapEnvVar('OUTPUT', 'hybrid');
// The FQDN of where the site is hosted (used for sitemaps & canonical URLs)
const site = unwrapEnvVar('SITE_URL', 'https://web-check.xyz');
// The base URL of the site (if serving from a subdirectory)
const base = unwrapEnvVar('BASE_URL', '/');
// Should run the app in boss-mode (requires extra configuration)
const isBossServer = unwrapEnvVar('BOSS_SERVER', false);
// Initialize Astro integrations
const integrations = [svelte(), react(), partytown(), sitemap()];
// Set the appropriate adapter, based on the deploy target
function getAdapter(target) {
switch(target) {
case 'vercel':
return vercelAdapter();
case 'netlify':
return netlifyAdapter();
case 'cloudflare':
return cloudflareAdapter();
case 'node':
return nodeAdapter({ mode: 'middleware' });
default:
throw new Error(`Unsupported deploy target: ${target}`);
}
}
const adapter = getAdapter(deployTarget);
// Print build information to console
console.log(
`\n\x1b[1m\x1b[35m Preparing to start build of Web Check.... \x1b[0m\n`,
`\x1b[35m\x1b[2mCompiling for "${deployTarget}" using "${output}" mode, `
+ `to deploy to "${site}" at "${base}"\x1b[0m\n`,
`\x1b[2m\x1b[36m🛟 For documentation and support, visit the GitHub repo: ` +
`https://github.com/lissy93/web-check \n`,
`💖 Found Web-Check useful? Consider sponsoring us on GitHub ` +
`to help fund maintenance & development.\x1b[0m\n`,
);
const redirects = {
'/about': '/check/about',
};
// Skip the marketing homepage for self-hosted users
if (!isBossServer && isBossServer !== true) {
redirects['/'] = '/check';
}
// Export Astro configuration
export default defineConfig({ output, base, integrations, site, adapter, redirects });