AT Mot — a bilingual (EN/FR) daily word game native to the AT Protocol.
1import { defineConfig } from 'vite';
2import metadata from './public/client-metadata.json' with { type: 'json' };
3
4// AT Protocol OAuth forbids `localhost` — use the loopback IP instead.
5const SERVER_HOST = '127.0.0.1';
6const SERVER_PORT = 12520;
7
8export default defineConfig({
9 server: { host: SERVER_HOST, port: SERVER_PORT },
10 build: { target: 'es2022', sourcemap: true },
11 plugins: [
12 {
13 // Wires the OAuth client_id / redirect_uri into the build.
14 // In production we use the real hosted client-metadata.json URL.
15 // In dev, atproto allows a special loopback `client_id` that encodes
16 // the redirect_uri + scope, so no public metadata document is needed.
17 name: 'atmot-oauth-envs',
18 config(_conf, { command }) {
19 if (command === 'build') {
20 process.env.VITE_OAUTH_CLIENT_ID = metadata.client_id;
21 process.env.VITE_OAUTH_REDIRECT_URI = metadata.redirect_uris[0];
22 } else {
23 const redirectUri = `http://${SERVER_HOST}:${SERVER_PORT}${new URL(metadata.redirect_uris[0]!).pathname}`;
24 process.env.VITE_OAUTH_CLIENT_ID =
25 `http://localhost?redirect_uri=${encodeURIComponent(redirectUri)}` +
26 `&scope=${encodeURIComponent(metadata.scope)}`;
27 process.env.VITE_OAUTH_REDIRECT_URI = redirectUri;
28 }
29 process.env.VITE_OAUTH_SCOPE = metadata.scope;
30 },
31 },
32 ],
33});