Skip to content

Commit

Permalink
perf: Add root layout
Browse files Browse the repository at this point in the history
  • Loading branch information
aXenDeveloper committed Oct 24, 2024
1 parent 0035fba commit bd636dd
Show file tree
Hide file tree
Showing 88 changed files with 5,437 additions and 104 deletions.
13 changes: 0 additions & 13 deletions apps/backend/src/app.controller.ts

This file was deleted.

4 changes: 0 additions & 4 deletions apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { Module } from '@nestjs/common';
import { join } from 'path';
import { VitNodeCoreModule } from 'vitnode-backend/app.module';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { DATABASE_ENVS, schemaDatabase } from './database/config';
import { PluginsModule } from './plugins/plugins.module';

Expand All @@ -18,7 +16,5 @@ import { PluginsModule } from './plugins/plugins.module';
}),
PluginsModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
8 changes: 0 additions & 8 deletions apps/backend/src/app.service.ts

This file was deleted.

4 changes: 0 additions & 4 deletions apps/backend/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { INestApplication } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { greet } from 'shared/core/test';
import { nestjsMainApp } from 'vitnode-backend/main';

import { AppModule } from './app.module';

async function bootstrap() {
const app: INestApplication = await NestFactory.create(AppModule);

// eslint-disable-next-line no-console
console.log(greet('test'));

void nestjsMainApp(app, {});
}
void bootstrap();
6 changes: 2 additions & 4 deletions apps/frontend/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { NextConfig } from 'next';
import createNextIntlPlugin from 'next-intl/plugin';

const withNextIntl = createNextIntlPlugin('./src/i18n.ts');
import VitNodeConfig from 'vitnode-frontend/next.config';

const nextConfig: NextConfig = {
// output: 'standalone',
Expand All @@ -12,4 +10,4 @@ const nextConfig: NextConfig = {
},
};

export default withNextIntl(nextConfig);
export default VitNodeConfig(nextConfig);
5 changes: 3 additions & 2 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"geist": "^1.3.1",
"next": "^15.0.1",
"next-intl": "3.23.1",
"react": "19.0.0-rc-69d4b800-20241021",
Expand All @@ -26,9 +27,9 @@
"@types/react-dom": "^18",
"autoprefixer": "^10.4.20",
"eslint-config-typescript-vitnode": "workspace:*",
"vitnode-shared": "workspace:*",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
"typescript": "^5",
"vitnode-shared": "workspace:*"
}
}
28 changes: 10 additions & 18 deletions apps/frontend/src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import { NextIntlClientProvider } from 'next-intl';
import { getLocale, getMessages } from 'next-intl/server';
import { GeistSans } from 'geist/font/sans';
import {
generateMetadataRootLayout,
RootLayout,
} from 'vitnode-frontend/views/layout/root-layout';

import './global.css';

export default async function LocaleLayout({
children,
}: {
children: React.ReactNode;
}) {
const locale = await getLocale();
const messages = await getMessages();
export const generateMetadata = generateMetadataRootLayout;

return (
<html lang={locale}>
<body>
<NextIntlClientProvider messages={messages}>
{children}
</NextIntlClientProvider>
</body>
</html>
);
export default function Layout(
props: Omit<React.ComponentProps<typeof RootLayout>, 'className'>,
) {
return <RootLayout className={GeistSans.className} {...props} />;
}
8 changes: 1 addition & 7 deletions apps/frontend/src/app/[locale]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { greet } from 'shared/core/test';
import { getMiddlewareData } from 'vitnode-frontend/api/get-middleware-data';

export default async function Home() {
const test = await getMiddlewareData();

// eslint-disable-next-line no-console
console.log(test);

export default function Home() {
return <div>{greet('test')}</div>;
}
7 changes: 7 additions & 0 deletions apps/frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default async function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return children;
}
7 changes: 7 additions & 0 deletions apps/frontend/src/app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use client';

import { NotFoundView } from 'vitnode-frontend/views/theme/views/not-found';

export default function NotFound() {
return <NotFoundView />;
}
14 changes: 13 additions & 1 deletion packages/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@ import {
InternalDatabaseModule,
} from './utils/database/database.module';

export const ABSOLUTE_PATHS = {
const internalPaths = {
backend: join(process.cwd(), 'src'),
frontend: join(process.cwd(), '..', 'frontend', 'src'),
uploads: join(process.cwd(), 'uploads'),
plugins: join(process.cwd(), 'src', 'plugins'),
};

export const ABSOLUTE_PATHS = {
plugins: internalPaths.plugins,
uploads: {
public: join(internalPaths.uploads, 'public'),
private: join(internalPaths.uploads, 'private'),
temp: join(internalPaths.uploads, 'temp'),
},
};

@Module({})
export class VitNodeCoreModule {
static register({
Expand Down
10 changes: 5 additions & 5 deletions packages/backend/src/core/middleware/middleware.controller.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Controller, Get } from '@nestjs/common';
import { ApiResponse, ApiTags } from '@nestjs/swagger';
import { ShowMiddlewareObj } from 'vitnode-shared/middleware/get.middleware.dto';
import { ShowMiddlewareObj } from 'vitnode-shared/middleware.dto';

import { GetMiddlewareService } from './services/get.middleware.service';
import { ShowMiddlewareService } from './services/show.middleware.service';

@ApiTags('Core')
@Controller('core/middleware')
export class MiddlewareController {
constructor(private readonly getService: GetMiddlewareService) {}
constructor(private readonly showService: ShowMiddlewareService) {}

@Get()
@ApiResponse({
status: 200,
type: ShowMiddlewareObj,
})
async get(): Promise<ShowMiddlewareObj> {
return this.getService.get();
async show(): Promise<ShowMiddlewareObj> {
return this.showService.show();
}
}
4 changes: 2 additions & 2 deletions packages/backend/src/core/middleware/middleware.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Module } from '@nestjs/common';

import { MiddlewareController } from './middleware.controller';
import { GetMiddlewareService } from './services/get.middleware.service';
import { ShowMiddlewareService } from './services/show.middleware.service';

@Module({
providers: [GetMiddlewareService],
providers: [ShowMiddlewareService],
controllers: [MiddlewareController],
})
export class CoreMiddlewareModule {}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { ABSOLUTE_PATHS } from '@/app.module';
import { getConfigFile } from '@/providers/config';
import { Injectable } from '@nestjs/common';
import { readdir, readFile } from 'fs/promises';
import { join } from 'path';
import { ManifestWithLang } from 'vitnode-shared/manifest.dto';
import { ShowMiddlewareObj } from 'vitnode-shared/middleware.dto';

@Injectable()
export class ShowMiddlewareService {
protected async getManifest({
langCodes,
}: {
langCodes: string[];
}): Promise<ManifestWithLang[]> {
return await Promise.all(
langCodes.map(async lang => {
const path = join(
ABSOLUTE_PATHS.uploads.public,
'assets',
lang,
'manifest.webmanifest',
);
const manifest = JSON.parse(
await readFile(path, 'utf8'),
) as ManifestWithLang;

return manifest;
}),
);
}

async show(): Promise<ShowMiddlewareObj> {
// TODO: Add cache
const config = getConfigFile();
const plugins = await readdir(ABSOLUTE_PATHS.plugins);

return {
languages: config.langs,
authorization: {
force_login: config.settings.authorization.force_login,
lock_register: config.settings.authorization.lock_register,
},
plugins: [
'admin',
...plugins.filter(plugin => !['plugins.module.ts'].includes(plugin)),
],
is_email_enabled: false, // TODO: Add email service
is_ai_enabled: false, // TODO: Add AI service
site_name: config.settings.main.site_name,
site_short_name: config.settings.main.site_short_name,
};
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DatabaseModuleArgs } from '@/utils/database/database.module';
import type { DatabaseModuleArgs } from '@/utils/database/database.module';

import { Inject, Injectable } from '@nestjs/common';

import coreSchemaDatabase from '../../database';
Expand Down
5 changes: 0 additions & 5 deletions packages/eslint-config-typescript-vitnode/eslint.shared.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,7 @@ export default [
'@typescript-eslint/no-unnecessary-qualifier': 'error',
'@typescript-eslint/no-useless-empty-export': 'error',
'@typescript-eslint/method-signature-style': 'warn',
'@typescript-eslint/no-import-type-side-effects': 'warn',
'newline-before-return': 'warn',
'@typescript-eslint/consistent-type-imports': [
'warn',
{ prefer: 'no-type-imports' },
],
'no-restricted-imports': [
'error',
{
Expand Down
9 changes: 9 additions & 0 deletions packages/frontend/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type core from '../../apps/frontend/src/plugins/core/langs/en.json';
import type admin from '../../apps/frontend/src/plugins/admin/langs/en.json';
import type welcome from '../../apps/frontend/src/plugins/welcome/langs/en.json';

type Messages = typeof core & typeof admin & typeof welcome;

declare global {
interface IntlMessages extends Messages {}
}
2 changes: 2 additions & 0 deletions packages/frontend/next.config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { NextConfig } from 'next';
export default function NextConfigDefault(config?: NextConfig): NextConfig;
47 changes: 47 additions & 0 deletions packages/frontend/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import createNextIntlPlugin from 'next-intl/plugin';
import * as dotenv from 'dotenv';
import { join } from 'path';

dotenv.config({
path: join(process.cwd(), '..', '..', '.env'),
});

const withNextIntl = createNextIntlPlugin('./src/i18n.ts');

const nextConfig = config => {
const ENVS = {
backend_url: process.env.NEXT_PUBLIC_BACKEND_URL,
frontend_url: process.env.NEXT_PUBLIC_FRONTEND_URL,
};

const urls = {
backend: new URL(ENVS.backend_url ?? 'http://localhost:8080'),
frontend: new URL(ENVS.frontend_url ?? 'http://localhost:3000'),
};

return {
...config,
devIndicators: {
appIsrStatus: false,
},
env: {
NEXT_PUBLIC_BACKEND_URL: ENVS.backend_url,
NEXT_PUBLIC_FRONTEND_URL: ENVS.frontend_url,
},
transpilePackages: ['lucide-react', 'vitnode-frontend', 'vitnode-shared'],
images: {
remotePatterns: [
{
protocol: urls.backend.protocol === 'https:' ? 'https' : 'http',
hostname: urls.backend.hostname,
port: urls.backend.port,
pathname: '/public/**',
},
],
},
};
};

export default function NextConfigDefault(config) {
return withNextIntl(nextConfig(config || {}));
}
2 changes: 1 addition & 1 deletion packages/frontend/src/api/get-middleware-data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ShowMiddlewareObj } from 'vitnode-shared/middleware/get.middleware.dto';
import { ShowMiddlewareObj } from 'vitnode-shared/middleware.dto';

import { fetcher } from './fetcher';

Expand Down
Loading

0 comments on commit bd636dd

Please sign in to comment.