-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
67 lines (61 loc) · 2.02 KB
/
vite.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
import { vitePlugin as remix } from '@remix-run/dev';
import { CorsOptions, defineConfig, type Plugin } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
import { readFileSync } from 'node:fs';
import type { IncomingMessage } from 'node:http';
import {
getAuthorizationServerOrigin,
isBuilderUrl,
} from './app/utils/origins.server';
export default defineConfig(({ mode }) => {
return {
plugins: [
remix({
future: {
v3_fetcherPersist: true,
v3_relativeSplatPath: true,
v3_throwAbortReason: true,
},
}),
tsconfigPaths(),
],
server: {
// Service-to-service OAuth token call requires a specified host for the wstd.dev domain
host: 'wstd.dev',
// Needed for SSL
proxy: {},
https: {
key: readFileSync('./https/privkey.pem'),
cert: readFileSync('./https/fullchain.pem'),
},
cors: ((
req: IncomingMessage,
callback: (error: Error | null, options: CorsOptions | null) => void
) => {
// Handle CORS preflight requests in development to mimic Remix production behavior
if (req.method === 'OPTIONS') {
if (req.headers.origin != null && req.url != null) {
const url = new URL(req.url, `https://${req.headers.host}`);
// Allow CORS for /logout path when requested from the authorization server
if (url.pathname === '/logout' && isBuilderUrl(url.href)) {
return callback(null, {
origin: getAuthorizationServerOrigin(url.href),
preflightContinue: false,
credentials: true,
});
}
}
// Respond with method not allowed for other preflight requests
return callback(null, {
preflightContinue: false,
optionsSuccessStatus: 405,
});
}
// Disable CORS for all other requests
return callback(null, {
origin: false,
});
}) as never,
},
};
});