Skip to content

Commit

Permalink
Merge pull request #400 from aXenDeveloper/refactor/move_config_from_…
Browse files Browse the repository at this point in the history
…frontend_to_backend

refactor: Move config from frontend to backend
  • Loading branch information
aXenDeveloper authored Jul 7, 2024
2 parents d2ab7f9 + c3ae182 commit e62b3d0
Show file tree
Hide file tree
Showing 85 changed files with 895 additions and 645 deletions.
5 changes: 3 additions & 2 deletions apps/backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ lerna-debug.log*
!/uploads/private/index.html
!/uploads/temp/index.html

# Migrations
# Configuration
/src/plugins/*/admin/database/migrations
/src/plugins/core/email.config.json
/src/plugins/core/utils/config.json
/src/plugins/core/utils/email.config.json
36 changes: 32 additions & 4 deletions apps/backend/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
# THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
# ------------------------------------------------------

enum AllowTypeFilesEnum {
all
images
images_videos
none
}

type AuthorizationAdminSessionsObj {
nav: [NavAdminPluginsAuthorization!]!
user: AuthorizationCurrentUserObj
Expand Down Expand Up @@ -103,6 +110,11 @@ type EditAdminSettingsObj {
site_name: String!
}

type EditorShowCoreMiddleware {
files: FilesEditorShowCoreMiddleware!
sticky: Boolean!
}

type FilesAdminPluginsObj {
admin_pages: Int!
admin_templates: Int!
Expand All @@ -120,6 +132,14 @@ type FilesAuthorizationCoreSessions {
total_max_storage: Int!
}

input FilesEditAdminEditorStyles {
allow_type: AllowTypeFilesEnum!
}

type FilesEditorShowCoreMiddleware {
allow_type: AllowTypeFilesEnum!
}

type GroupUser {
id: Int!
name: [TextLanguage!]!
Expand Down Expand Up @@ -176,10 +196,7 @@ type Mutation {
admin__core_main_settings__edit(site_copyright: [TextLanguageInput!]!, site_description: [TextLanguageInput!]!, site_name: String!, site_short_name: String!): EditAdminSettingsObj!
admin__core_manifest_metadata__edit(background_color: String!, display: String!, start_url: String!, theme_color: String!): ShowAdminManifestMetadataObj!
admin__core_members__edit(birthday: DateTime!, email: String!, first_name: String!, id: Int!, last_name: String!, name: String!, newsletter: Boolean!): EditAdminMembersObj!
admin__core_nav__change_position(id: Int!, index_to_move: Int!, parent_id: Int!): String!
admin__core_nav__create(description: [TextLanguageInput!]!, external: Boolean!, href: String!, icon: String, name: [TextLanguageInput!]!): ShowCoreNav!
admin__core_nav__delete(id: Int!): String!
admin__core_nav__edit(description: [TextLanguageInput!]!, external: Boolean!, href: String!, icon: String, id: Int!, name: [TextLanguageInput!]!): ShowCoreNav!
admin__core_nav_styles__change_position(id: Int!, index_to_move: Int!, parent_id: Int!): String!
admin__core_plugins__create(author: String!, author_url: String, code: String!, description: String, name: String!, support_url: String!): ShowAdminPlugins!
admin__core_plugins__delete(code: String!): String!
admin__core_plugins__download(code: String!, version: String, version_code: Int): String!
Expand All @@ -193,6 +210,10 @@ type Mutation {
admin__core_staff_administrators__delete(id: Int!): String!
admin__core_staff_moderators__create(group_id: Int, unrestricted: Boolean!, user_id: Int): ShowAdminStaffModerators!
admin__core_staff_moderators__delete(id: Int!): String!
admin__core_styles__editor__edit(files: FilesEditAdminEditorStyles!, sticky: Boolean!): EditorShowCoreMiddleware!
admin__core_styles__nav__create(description: [TextLanguageInput!]!, external: Boolean!, href: String!, icon: String, name: [TextLanguageInput!]!): ShowCoreNav!
admin__core_styles__nav__delete(id: Int!): String!
admin__core_styles__nav__edit(description: [TextLanguageInput!]!, external: Boolean!, href: String!, icon: String, id: Int!, name: [TextLanguageInput!]!): ShowCoreNav!
admin__core_theme_editor__edit(colors: ColorsEditAdminThemeEditor!): String!
admin__install__create_database: String!
admin_sessions__sign_out: String!
Expand Down Expand Up @@ -257,6 +278,11 @@ type Query {
core_theme_editor__show: ShowCoreThemeEditorObj!
}

type RebuildRequiredEditorShowCoreMiddleware {
langs: Boolean!
plugins: Boolean!
}

type ShowAdminEmailSettingsServiceObj {
color_primary: String!
smtp_host: String!
Expand Down Expand Up @@ -556,8 +582,10 @@ enum ShowCoreMembersSortingColumnEnum {
}

type ShowCoreMiddlewareObj {
editor: EditorShowCoreMiddleware!
languages: [LanguagesCoreMiddleware!]!
plugins: [String!]!
rebuild_required: RebuildRequiredEditorShowCoreMiddleware!
}

type ShowCoreNav {
Expand Down
1 change: 0 additions & 1 deletion apps/docs/pages/docs/deployment/install.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,4 @@ Now, let's move to the [security server](setup/secure) part.
sudo docker rm -v -f $(docker ps -qa)
sudo docker rmi $(docker images -a -q)
sudo docker system prune -a
sudo rm -r /home/vitnode/docker && sudo rm /home/vitnode/frontend/utils/config.json
```
1 change: 0 additions & 1 deletion apps/frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
utils/config.json

/public/assets
/public/uploads
4 changes: 0 additions & 4 deletions apps/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ ENV NEXT_TELEMETRY_DISABLED 1

RUN pnpm turbo build --filter=frontend...

# COPY frontend/utils/config.json ./frontend/utils/config.json

FROM base AS runner
WORKDIR /app

Expand All @@ -55,11 +53,9 @@ WORKDIR /app
# # https://nextjs.org/docs/advanced-features/output-file-tracing
# COPY --from=installer --chown=nextjs:nodejs /app/frontend/.next/standalone ./
# COPY --from=installer --chown=nextjs:nodejs /app/frontend/.next/static ./frontend/.next/static
# COPY --from=installer --chown=nextjs:nodejs /app/frontend/utils/config.json ./frontend/utils/config.json

COPY --from=installer /app/frontend/.next/standalone ./
COPY --from=installer /app/frontend/.next/static ./frontend/.next/static
COPY --from=installer /app/frontend/utils/config.json ./frontend/config.json

EXPOSE 3000
ENV PORT 3000
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Metadata } from 'next';
import { getTranslations } from 'next-intl/server';
import * as React from 'react';
import { getConfigFile } from 'vitnode-frontend/helpers/config';
import { getGlobalData } from 'vitnode-frontend/graphql/get-global-data';

interface Props {
children: React.ReactNode;
}

export async function generateMetadata(): Promise<Metadata> {
const [config, t, tAdmin] = await Promise.all([
getConfigFile(),
const [data, t, tAdmin] = await Promise.all([
getGlobalData(),
getTranslations('blog.admin.nav'),
getTranslations('admin'),
]);

const defaultTitle = `${t('title')} - ${tAdmin('title_short')} - ${config.settings.general.site_name}`;
const defaultTitle = `${t('title')} - ${tAdmin('title_short')} - ${data.core_settings__show.site_name}`;

return {
title: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { getTranslations } from 'next-intl/server';
import * as React from 'react';
import { Metadata } from 'next';
import { getConfigFile } from 'vitnode-frontend/helpers/config';
import { getGlobalData } from 'vitnode-frontend/graphql/get-global-data';

interface Props {
children: React.ReactNode;
}

export async function generateMetadata(): Promise<Metadata> {
const [t, tCore, config] = await Promise.all([
const [t, tCore, data] = await Promise.all([
getTranslations('admin'),
getTranslations('core.admin'),
getConfigFile(),
getGlobalData(),
]);

const defaultTitle = `${tCore('nav.settings')} - ${t('title_short')} - ${config.settings.general.site_name}`;
const defaultTitle = `${tCore('nav.settings')} - ${t('title_short')} - ${data.core_settings__show.site_name}`;

return {
title: {
Expand Down
8 changes: 4 additions & 4 deletions apps/frontend/app/[locale]/(admin)/admin/(auth)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { getTranslations } from 'next-intl/server';
import { Metadata } from 'next';
import { getConfigFile } from 'vitnode-frontend/helpers/config';
import { getGlobalData } from 'vitnode-frontend/graphql/get-global-data';
import { AdminLayout } from 'vitnode-frontend/views/admin/layout/admin-layout';
import { AuthAdminLayout } from 'vitnode-frontend/views/admin/layout/auth/auth-admin-layout';

Expand All @@ -10,12 +10,12 @@ interface Props {
}

export async function generateMetadata(): Promise<Metadata> {
const [config, t] = await Promise.all([
getConfigFile(),
const [data, t] = await Promise.all([
getGlobalData(),
getTranslations('admin'),
]);

const defaultTitle = `${t('title_short')} - ${config.settings.general.site_name}`;
const defaultTitle = `${t('title_short')} - ${data.core_settings__show.site_name}`;

return {
title: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import * as React from 'react';
import { Metadata } from 'next';
import { getTranslations } from 'next-intl/server';
import { getConfigFile } from 'vitnode-frontend/helpers/config';
import { LayoutSettingsView } from 'vitnode-frontend/theme-tsx/settings/layout-settings-view';
import { getGlobalData } from 'vitnode-frontend/graphql/get-global-data';

interface Props {
children: React.ReactNode;
}

export async function generateMetadata(): Promise<Metadata> {
const config = await getConfigFile();
const t = await getTranslations('core.settings');
const [data, t] = await Promise.all([
getGlobalData(),
getTranslations('core.settings'),
]);

return {
title: {
default: t('title'),
template: `%s - ${t('title')} - ${config.settings.general.site_name}`,
template: `%s - ${t('title')} - ${data.core_settings__show.site_name}`,
},
robots: 'noindex, nofollow',
};
Expand Down
10 changes: 5 additions & 5 deletions apps/frontend/app/[locale]/(main)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ const getDescription = async ({
locale: Props['params']['locale'];
}): Promise<string> => {
const {
data: {
core_settings__show: { site_description },
},
core_settings__show: { site_description },
} = await getSessionData();

const textFromLang = site_description.find(t => t.language_code === locale);
Expand All @@ -37,11 +35,13 @@ export async function generateMetadata({
}

export default async function Page() {
const { default_plugin } = await getSessionData();
const {
core_sessions__authorization: { plugin_default },
} = await getSessionData();
const PageFromTheme: React.LazyExoticComponent<() => JSX.Element> =
React.lazy(
async () =>
import(`../../../plugins/${default_plugin}/templates/default-page`),
import(`../../../plugins/${plugin_default}/templates/default-page`),
);

return <PageFromTheme />;
Expand Down
6 changes: 2 additions & 4 deletions apps/frontend/app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ const generateAlternateLanguagesForSitemap = ({

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const {
data: {
core_languages__show: { edges: languages },
core_plugins__show,
},
core_languages__show: { edges: languages },
core_plugins__show,
} = await getSessionData();
const plugins = core_plugins__show.filter(item => item.allow_default);

Expand Down
3 changes: 1 addition & 2 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"author": "Maciej Piotr (aXenDev) Balcerzak",
"license": "GPL-3.0 license",
"scripts": {
"config:init": "vitnode-frontend init",
"dev": "pnpm config:init && next dev --turbo",
"dev": "next dev --turbo",
"dev:turbo": "next dev --turbo",
"build": "next build",
"analyze": "cross-env ANALYZE=true pnpm build",
Expand Down
Loading

0 comments on commit e62b3d0

Please sign in to comment.