-
Notifications
You must be signed in to change notification settings - Fork 1
/
astro.config.ts
executable file
·157 lines (151 loc) · 5 KB
/
astro.config.ts
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
import { defineConfig } from 'astro/config';
import tailwind from '@astrojs/tailwind';
import react from '@astrojs/react';
import node from '@astrojs/node';
import mdx from '@astrojs/mdx';
import keystatic from '@keystatic/astro';
import { join } from 'node:path';
import { readdirSync, readFileSync } from 'node:fs';
import matter from 'gray-matter';
import sitemap from '@astrojs/sitemap';
const contentDir = join(import.meta.dirname, 'src', 'content');
const siteUrl = 'https://www.glass.no';
function getRoutes(directory: string, prefix: string = '') {
return readdirSync(join(contentDir, directory))
.filter((file) => file.endsWith('.md'))
.map((file) => {
const content = readFileSync(join(contentDir, directory, file), 'utf-8');
const { data } = matter(content);
const slug = file.replace('.mdx', '');
if (data.navigationTitle) {
switch (directory) {
case 'pages':
case 'posts':
return `${prefix}/${slug}`;
case 'glasstypes':
return `${prefix}/glasstyper/${slug}`;
default:
return `${prefix}/${slug.toLowerCase().replace(/\s+/g, '-')}`;
}
}
return null;
})
.filter(Boolean);
}
const pageRoutes = getRoutes('pages', siteUrl);
const postRoutes = getRoutes('posts', siteUrl);
const glasstypeRoutes = getRoutes('glasstypes', siteUrl);
// https://astro.build/config
export default defineConfig({
site: siteUrl,
server: {
headers: {
// CORS headers
// 'Access-Control-Allow-Origin': 'https://*.glass.no',
// 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
// 'Access-Control-Allow-Headers': 'Content-Type, Authorization',
// 'Access-Control-Allow-Credentials': 'true',
// // Security headers
// 'Cross-Origin-Opener-Policy': 'same-origin-allow-popups', // Less restrictive than 'same-origin' to allow third-party auth
// 'Cross-Origin-Embedder-Policy': 'require-corp',
// 'Cross-Origin-Resource-Policy': 'cross-origin', // Allow resources from subdomains
// Standard security headers
// 'X-Content-Type-Options': 'nosniff',
// 'X-Frame-Options': 'SAMEORIGIN',
// 'X-XSS-Protection': '1; mode=block',
// 'Referrer-Policy': 'strict-origin-when-cross-origin',
// // HSTS (Strict Transport Security)
// 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload',
// Content Security Policy - more permissive for subdomains
// 'Content-Security-Policy': `
// default-src 'self' https://*.glass.no;
// script-src 'self' https://*.glass.no 'unsafe-inline';
// style-src 'self' https://*.glass.no 'unsafe-inline';
// img-src 'self' https://*.glass.no data: blob:;
// font-src 'self' https://*.glass.no;
// connect-src 'self' https://*.glass.no;
// media-src 'self' https://*.glass.no;
// object-src 'none';
// frame-src 'self' https://*.glass.no;
// base-uri 'self';
// form-action 'self' https://*.glass.no;
// frame-ancestors 'self';
// upgrade-insecure-requests;
// `
// .replace(/\s+/g, ' ')
// .trim(),
},
},
redirects: {
'/10-mater-a-bruke-smijern-i-ditt-hjem': {
status: 301,
destination: '/hvordan-bruke-smijernsdører-10-tips',
},
'/posts/10-mater-a-bruke-smijern-i-ditt-hjem': {
status: 301,
destination: '/hvordan-bruke-smijernsdører-10-tips',
},
'/hvordan-bruke-smijernsdører': {
status: 301,
destination: '/hvordan-bruke-smijernsdører-10-tips',
},
'/posts/glassrekverk-renovasjon-av-hjemmet-med-riktig-glassdesing': {
status: 301,
destination: '/glassrekkverk',
},
'/glassrekverk-renovasjon-av-hjemmet-med-riktig-glassdesing': {
status: 301,
destination: '/glassrekkverk',
},
'/odelagt-vindusglass': {
status: 301,
destination: '/vindusglass',
},
'/hva-er-glassmester-copy': {
status: 301,
destination: '/hva-er-glassmester',
},
'/rengjoring-av-metalldor': {
status: 301,
destination: '/vedlikehold-av-smijernsdorer-slik-gjor-du-det',
},
'/posts/rengjoring-av-metalldor': {
status: 301,
destination: '/vedlikehold-av-smijernsdorer-slik-gjor-du-det',
},
'/posts/[slug]': '/[slug]',
'/booking': {
status: 301,
destination: '/befaring',
},
},
vite: {
build: {
rollupOptions: {
external: ['path', 'url'],
},
},
},
integrations: [
tailwind({
applyBaseStyles: false,
}),
react({ experimentalReactChildren: true }),
mdx(),
keystatic(),
sitemap({
customPages: [...pageRoutes, ...postRoutes, ...glasstypeRoutes].filter(Boolean) as string[],
changefreq: 'weekly',
priority: 0.7,
lastmod: new Date('2024-10-22'),
}),
],
trailingSlash: 'never',
build: {
format: 'directory',
},
output: 'hybrid',
adapter: node({
mode: 'standalone',
}),
});