config vite for oauth
This commit is contained in:
parent
b251074253
commit
e53ebcfbfd
3 changed files with 69 additions and 2 deletions
|
|
@ -1,7 +1,44 @@
|
|||
import tailwindcss from '@tailwindcss/vite';
|
||||
import { sveltekit } from '@sveltejs/kit/vite';
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
import { defineConfig } from 'vite';
|
||||
import metadata from './src/lib/client-metadata.json' with { type: 'json' };
|
||||
|
||||
const SERVER_HOST = '127.0.0.1';
|
||||
const SERVER_PORT = 12520;
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [tailwindcss(), sveltekit()]
|
||||
server: {
|
||||
host: SERVER_HOST,
|
||||
port: SERVER_PORT
|
||||
},
|
||||
plugins: [
|
||||
sveltekit(),
|
||||
tailwindcss(),
|
||||
{
|
||||
name: 'oauth-env-injection',
|
||||
config(_conf, { command }) {
|
||||
if (command === 'build') {
|
||||
process.env.VITE_OAUTH_CLIENT_ID = metadata.client_id;
|
||||
process.env.VITE_OAUTH_REDIRECT_URI = metadata.redirect_uris[0];
|
||||
} else {
|
||||
const redirectUri = (() => {
|
||||
const url = new URL(metadata.redirect_uris[0]);
|
||||
return `http://${SERVER_HOST}:${SERVER_PORT}${url.pathname}`;
|
||||
})();
|
||||
|
||||
const clientId =
|
||||
`http://localhost` +
|
||||
`?redirect_uri=${encodeURIComponent(redirectUri)}` +
|
||||
`&scope=${encodeURIComponent(metadata.scope)}`;
|
||||
|
||||
process.env.VITE_DEV_SERVER_PORT = '' + SERVER_PORT;
|
||||
process.env.VITE_OAUTH_CLIENT_ID = clientId;
|
||||
process.env.VITE_OAUTH_REDIRECT_URI = redirectUri;
|
||||
}
|
||||
|
||||
process.env.VITE_CLIENT_URI = metadata.client_uri;
|
||||
process.env.VITE_OAUTH_SCOPE = metadata.scope;
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue