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

Build issues with globals.title and globals.theme #126

Open
JSDA123 opened this issue Nov 20, 2024 · 1 comment
Open

Build issues with globals.title and globals.theme #126

JSDA123 opened this issue Nov 20, 2024 · 1 comment

Comments

@JSDA123
Copy link

JSDA123 commented Nov 20, 2024

For some reason globals.title and globals.theme are not applied during build. After changing these fields in Directus, the changes are not seen after building the frontend.

In the page metadata, there remain references to 'AgencyOS', making it unsuitable for production.

For example:
<meta property="og:site_name" content="AgencyOS">

And:
<script type="application/ld+json" id="schema-org-graph" ... "@type":"WebSite","name":"AgencyOS", ... </script></body></html>

I'm new to Nuxt so I can't quite see where it is going wrong. Any suggestions?

@Lukienlong
Copy link

当我想更改globals.theme时也遇到了同样的问题。以下是我的解决方法:
When I wanted to change globals.theme, I encountered the same problem. Here is my solution:
根据directus的文档,创建websocket连接,并订阅globals,手动对前端信息进行更新。
According to the Directus documentation, create a websocket connection and subscribe to globals, manually updating front-end information.
以下为部分代码:
The following is part of the code:
app.vue

onMounted(() => {
	const baseUrl = useRuntimeConfig().public.directus.rest.baseUrl;
	const access_token = useRuntimeConfig().public.directus.rest.token;
	const url = baseUrl.replace(/^https?:\/\//, '');
	const ws = new WebSocket(`ws://${url}/websocket`);
	ws.addEventListener('open', function (e) {
		console.log('ws open');
		ws.send(
			JSON.stringify({
				type: 'auth',
				access_token,
			}),
		);
	});
	ws.addEventListener('message', function (message) {
		const data = JSON.parse(message.data);
		if (data.type === 'ping') {
			ws.send(
				JSON.stringify({
					type: 'pong',
				}),
			);
		} else if (data.type === 'auth' && data.status === 'ok') {
			ws.send(
				JSON.stringify({
					type: 'subscribe',
					collection: 'globals',
					query: { fields: ['*'] },
				}),
			);
		}
		else if (data.type === 'subscription'){
			if (data.event === 'update'){
				updateAppConfig({ ui:{
					primary: data.data[0].theme.primary,
					gray: data.data[0].theme.gray,
				} });
			}
		}
	});
	ws.addEventListener('close', function (e) {
		console.log('ws closed');
	});
	ws.addEventListener('error', function (error) {
		console.log('ws error');
		console.error(error);
	});
});

nuxt.config.ts

	// Directus Configuration
	directus: {
		rest: {
			baseUrl: process.env.DIRECTUS_URL || 'http://localhost:8055',
			nuxtBaseUrl: process.env.NUXT_PUBLIC_SITE_URL || 'http://localhost:3000',
			token: process.env.DIRECTUS_SERVER_TOKEN || '',
		},
		auth: {
			enabled: true,
			enableGlobalAuthMiddleware: false, // Enable auth middleware on every page
			userFields: ['*', { contacts: ['*'] }], // Select user fields
			redirect: {
				login: '/auth/signin', // Path to redirect when login is required
				logout: '/', // Path to redirect after logout
				home: '/portal', // Path to redirect after successful login
				resetPassword: '/auth/reset-password', // Path to redirect for password reset
				callback: '/auth/callback', // Path to redirect after login with provider
			},
		},
	},

.env

DIRECTUS_URL="http://localhost:8055"
DIRECTUS_SERVER_TOKEN="jymD0l2RuM1pP52-hzCLiHZd39KW352D"
SITE_URL="http://localhost:3000"

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

No branches or pull requests

2 participants