Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use appName directly from .env in <title> #292

Merged
merged 2 commits into from
Jun 21, 2023

Conversation

domnantas
Copy link
Contributor

@domnantas domnantas commented Jun 19, 2023

Currently, appName in app.tsx is pulled via DOM from app.blade.php <title> tag. It works, but using it from .env seems like a better approach. Additionally, it serves as an example of how .env variables should be accessed in React/Vue.

The ssr templates had 'Laravel' hardcoded as the app name, which is not great for SEO. Replaced those parts with import.meta.env.VITE_APP_NAME as well.

This depends on laravel/laravel#6204 where I added VITE_APP_NAME as an alias to APP_NAME

I don't think any changes in this PR could be considered breaking.

Similar issue fixed in Jetstream: laravel/jetstream#1329

@@ -4,7 +4,7 @@ import createServer from '@inertiajs/react/server';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import route from '../../vendor/tightenco/ziggy/dist/index.m';

const appName = 'Laravel';
const appName = import.meta.env.VITE_APP_NAME || 'Laravel';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ssr can also use process.env to access envs (even without the VITE_ prefix)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that it is consistent and uses VITE_APP_NAME, otherwise if you remove that ENV it could work in SSR and not a normal build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Using process.env would be a good example of accessing secrets/api keys and not exposing them to the frontend, but using it here would be a little misleading

@domnantas domnantas changed the title Use appName from .env in <title> Use appName directly from .env in <title> Jun 19, 2023
@driesvints
Copy link
Member

Tests fail here.

@taylorotwell taylorotwell marked this pull request as draft June 20, 2023 12:06
@timacdonald
Copy link
Member

I've created a fix for the TS failure here: #293

It is unrelated to this PR.

@driesvints driesvints marked this pull request as ready for review June 21, 2023 07:02
@taylorotwell taylorotwell merged commit 08f4c2e into laravel:1.x Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants