fix: app base url shared in inertia config file

This commit is contained in:
Sonny
2025-08-21 02:25:16 +02:00
parent 5f7fad26fa
commit 18fe979069
5 changed files with 24 additions and 10 deletions

View File

@@ -1,16 +1,22 @@
# node ace generate:key
APP_KEY=soY8ZAtItT_fCkNUADfgffZUUo675lOj
# App
TZ=UTC
PORT=3333
HOST=localhost
LOG_LEVEL=info
LOG_LEVEL=debug
APP_KEY=soY8ZAtItT_fCkNUADfgffZUUo675lOj # node ace generate:key
NODE_ENV=development
SESSION_DRIVER=cookie
# App url
APP_URL=http://localhost:3333
# Database
DB_HOST=127.0.0.1
DB_PORT=5432
DB_USER=root
DB_PASSWORD=root
DB_DATABASE=app
# Google
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_CLIENT_CALLBACK_URL=http://localhost:3333/auth/callback

View File

@@ -5,7 +5,7 @@ const allyConfig = defineConfig({
google: services.google({
clientId: env.get('GOOGLE_CLIENT_ID'),
clientSecret: env.get('GOOGLE_CLIENT_SECRET'),
callbackUrl: env.get('GOOGLE_CLIENT_CALLBACK_URL'),
callbackUrl: env.get('APP_URL') + '/auth/callback',
prompt: 'select_account',
display: 'page',
scopes: ['userinfo.email', 'userinfo.profile'],

View File

@@ -1,4 +1,5 @@
import { isSSREnableForPage } from '#config/ssr';
import env from '#start/env';
import { DEFAULT_USER_THEME, KEY_USER_THEME } from '#user/constants/theme';
import logger from '@adonisjs/core/services/logger';
import { defineConfig } from '@adonisjs/inertia';
@@ -24,6 +25,7 @@ export default defineConfig({
isAuthenticated: ctx.auth?.isAuthenticated || false,
};
},
appUrl: env.get('APP_URL'),
},
/**

View File

@@ -1,7 +1,6 @@
import { api } from '#adonis/api';
import { PRIMARY_COLOR } from '#config/project';
import { PageProps } from '@adonisjs/inertia/types';
import { router, usePage } from '@inertiajs/react';
import { router } from '@inertiajs/react';
import {
ColorSchemeScript,
createTheme,
@@ -15,6 +14,7 @@ import { TuyauProvider } from '@tuyau/inertia/react';
import dayjs from 'dayjs';
import { ReactNode, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { useAppUrl } from '~/hooks/use_app_url';
import '../styles/index.css';
const TRANSITION_IN_CLASS = '__transition_fadeIn';
@@ -73,12 +73,12 @@ const customTheme = createTheme({
export function BaseLayout({ children }: { children: ReactNode }) {
const { i18n } = useTranslation();
const appUrl = useAppUrl();
dayjs.locale(i18n.language);
const { props } = usePage<PageProps & { appBaseUrl: string }>();
const tuyauClient = createTuyau({
api,
baseUrl: props.appBaseUrl,
baseUrl: appUrl,
});
const findAppElement = () => document.getElementById('app');

View File

@@ -27,6 +27,13 @@ export default await Env.create(new URL('../', import.meta.url), {
/*
|----------------------------------------------------------
| Variables for configuring app url
|----------------------------------------------------------
*/
APP_URL: Env.schema.string({ format: 'url', tld: false }), // Remove TLD to allow localhost
/*
|----------------------------------------------------------
| Variables for configuring database connection
|----------------------------------------------------------
*/
@@ -43,5 +50,4 @@ export default await Env.create(new URL('../', import.meta.url), {
*/
GOOGLE_CLIENT_ID: Env.schema.string(),
GOOGLE_CLIENT_SECRET: Env.schema.string(),
GOOGLE_CLIENT_CALLBACK_URL: Env.schema.string(),
});