interactive intro to open social
at-me.zzstoatzz.io
1import { defineConfig } from 'vite';
2import metadata from './public/oauth-client-metadata.json' with { type: 'json' };
3
4const SERVER_HOST = '127.0.0.1';
5const SERVER_PORT = 3030;
6
7export default defineConfig({
8 root: '.',
9 publicDir: 'public',
10 base: './',
11 build: {
12 outDir: 'dist',
13 rollupOptions: {
14 input: {
15 main: 'index.html',
16 view: 'view.html',
17 'view-dir': 'view/index.html'
18 }
19 }
20 },
21 server: {
22 host: SERVER_HOST,
23 port: SERVER_PORT
24 },
25 appType: 'mpa',
26 plugins: [
27 // Inject OAuth environment variables
28 {
29 name: 'oauth-env',
30 config(_conf, { command }) {
31 if (command === 'build') {
32 process.env.VITE_OAUTH_CLIENT_ID = metadata.client_id;
33 process.env.VITE_OAUTH_REDIRECT_URI = metadata.redirect_uris[0];
34 } else {
35 // Dev mode: use localhost client ID format
36 const redirectUri = `http://${SERVER_HOST}:${SERVER_PORT}/view.html`;
37 const clientId =
38 `http://localhost` +
39 `?redirect_uri=${encodeURIComponent(redirectUri)}` +
40 `&scope=${encodeURIComponent(metadata.scope)}`;
41
42 process.env.VITE_OAUTH_CLIENT_ID = clientId;
43 process.env.VITE_OAUTH_REDIRECT_URI = redirectUri;
44 }
45 process.env.VITE_OAUTH_SCOPE = metadata.scope;
46 }
47 },
48 // Rewrite /view/ to /view.html for dev server
49 {
50 name: 'rewrite-view',
51 configureServer(server) {
52 server.middlewares.use((req, res, next) => {
53 if (req.url.startsWith('/view') && !req.url.includes('.html')) {
54 // /view/ or /view/?query -> /view.html or /view.html?query
55 req.url = req.url.replace(/^\/view\/?/, '/view.html');
56 }
57 next();
58 });
59 }
60 }
61 ]
62});