-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathastro.config.mts
More file actions
210 lines (195 loc) · 4.82 KB
/
astro.config.mts
File metadata and controls
210 lines (195 loc) · 4.82 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import mdx from "@astrojs/mdx";
import react from "@astrojs/react";
import sitemap from "@astrojs/sitemap";
import { shield } from "@kindspells/astro-shield";
import sentry from "@sentry/astro";
import tailwindcss from "@tailwindcss/vite";
import AstroPWA from "@vite-pwa/astro";
import type { AstroIntegration } from "astro";
import { defineConfig, envField } from "astro/config";
import childProcess from "node:child_process";
import crypto from "node:crypto";
import fs from "node:fs";
import { resolve } from "node:path";
const pwa = AstroPWA({
devOptions: {
type: "module",
enabled: false,
},
selfDestroying: true,
registerType: "autoUpdate",
workbox: {
globPatterns: [
"**/*.{css,js,json,webp,svg,png,ico,woff2,mp4,vtf,vmt,html}",
],
},
includeAssets: ["**/*.{png,xml,ico,svg,webp,mp4,vtf,vmt}"],
manifest: {
name: "mastercomfig",
short_name: "mastercomfig",
categories: ["games", "utilities", "personalization"],
lang: "en-US",
dir: "ltr",
orientation: "any",
icons: [
{
src: "/android-chrome-192x192.png",
type: "image/png",
sizes: "192x192",
purpose: "maskable",
},
{
src: "/android-chrome-512x512.png",
type: "image/png",
sizes: "512x512",
purpose: "maskable",
},
{
src: "/img/mastercomfig_logo_192x.png",
type: "image/png",
sizes: "192x192",
purpose: "any",
},
{
src: "/img/mastercomfig_logo_512x.png",
type: "image/png",
sizes: "512x512",
purpose: "any",
},
],
start_url: "/app?source=pwa",
background_color: "#212121",
display: "standalone",
display_override: ["standalone", "minimal-ui", "browser"],
scope: "/",
theme_color: "#009688",
description: "Manage your mastercomfig installation",
},
experimental: {
directoryAndTrailingSlashHandler: true,
},
});
const rootDir = new URL(".", import.meta.url).pathname;
const nonce = crypto.randomBytes(16).toString("base64");
const astroCSPHashExporter: AstroIntegration = {
name: "astro-csp-hash-exporter",
hooks: {
"astro:build:done": async () => {
if (import.meta.env.DEV) {
return;
}
const nonceFileWritePath = resolve(rootDir, "generated", "nonce.txt");
fs.writeFileSync(nonceFileWritePath, nonce);
const process = childProcess.fork(
resolve(rootDir, "scripts", "generate-headers-file.js"),
);
return new Promise((resolve, reject) => {
process.on("error", function (err) {
if (!err) return;
reject(err);
});
process.on("exit", function (code) {
const err = code === 0 ? null : new Error("exit code " + code);
if (!err) resolve();
reject(err);
});
});
},
},
};
const astroCSPHashExporterSetup: AstroIntegration = {
name: "astro-csp-hash-exporter",
hooks: {
"astro:config:setup": async ({ updateConfig }) => {
updateConfig({ integrations: [astroCSPHashExporter] });
},
},
};
const modulePath = import.meta.env.DEV
? undefined
: resolve(rootDir, "generated", "sriHashes.mjs");
const defaultHost = "comfig.app";
const hostname = process.env["ASTRO_DOMAIN_OVERRIDE"] || defaultHost;
// https://astro.build/config
export default defineConfig({
site: `https://${hostname}`,
integrations: [
react(),
pwa,
sentry({
sourceMapsUploadOptions: {
org: "mastercoms",
project: "comfig-app",
authToken: process.env.SENTRY_AUTH_TOKEN ?? "",
},
}),
shield({
sri: {
hashesModule: modulePath,
},
}),
astroCSPHashExporterSetup,
sitemap(),
mdx(),
],
image: {
remotePatterns: [
{
protocol: "https",
hostname: "teamwork.tf",
},
{
protocol: "https",
hostname: "wiki.teamfortress.com",
},
{
protocol: "https",
hostname: "tf2maps.net",
},
{
protocol: "https",
hostname: "comp.tf",
},
{
protocol: "https",
hostname: "steamuserimages-a.akamaihd.net",
},
{
protocol: "https",
hostname: "images.steamusercontent.com",
},
],
},
build: {
inlineStylesheets: "never",
},
vite: {
build: {
sourcemap: true,
assetsInlineLimit: 0,
},
html: {
cspNonce: nonce,
},
resolve: {
alias: {
"~bootstrap": resolve(rootDir, "node_modules", "bootstrap"),
"~bootswatch": resolve(rootDir, "node_modules", "bootswatch"),
},
},
plugins: [tailwindcss()],
},
prefetch: false,
env: {
schema: {
NONCE: envField.string({
context: "server",
access: "secret",
default: nonce,
}),
},
},
experimental: {
clientPrerender: true,
},
});