Add Next.js project with internationalization support
- Set up Next.js 15 with TypeScript, ESLint, and Tailwind CSS - Add i18n support for Korean, English, and Japanese - Implement language switcher and navigation components - Update .gitignore to exclude node_modules, IDE files, and build artifacts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
20
.gitignore
vendored
20
.gitignore
vendored
@@ -77,3 +77,23 @@ fabric.properties
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
# ---> Node.js
|
||||
# Dependencies
|
||||
node_modules/
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
|
||||
# ---> Next.js
|
||||
.next/
|
||||
out/
|
||||
dist/
|
||||
build/
|
||||
|
||||
# ---> IDE
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
# ---> Claude
|
||||
claudedocs/
|
||||
|
||||
18
eslint.config.mjs
Normal file
18
eslint.config.mjs
Normal file
@@ -0,0 +1,18 @@
|
||||
import { defineConfig, globalIgnores } from "eslint/config";
|
||||
import nextVitals from "eslint-config-next/core-web-vitals";
|
||||
import nextTs from "eslint-config-next/typescript";
|
||||
|
||||
const eslintConfig = defineConfig([
|
||||
...nextVitals,
|
||||
...nextTs,
|
||||
// Override default ignores of eslint-config-next.
|
||||
globalIgnores([
|
||||
// Default ignores of eslint-config-next:
|
||||
".next/**",
|
||||
"out/**",
|
||||
"build/**",
|
||||
"next-env.d.ts",
|
||||
]),
|
||||
]);
|
||||
|
||||
export default eslintConfig;
|
||||
6
next-env.d.ts
vendored
Normal file
6
next-env.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
/// <reference path="./.next/types/routes.d.ts" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||
10
next.config.ts
Normal file
10
next.config.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { NextConfig } from "next";
|
||||
import createNextIntlPlugin from 'next-intl/plugin';
|
||||
|
||||
const withNextIntl = createNextIntlPlugin('./src/i18n/request.ts');
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
/* config options here */
|
||||
};
|
||||
|
||||
export default withNextIntl(nextConfig);
|
||||
6243
package-lock.json
generated
Normal file
6243
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
package.json
Normal file
30
package.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "sma-next-project",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "eslint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hookform/resolvers": "^5.2.2",
|
||||
"next": "^15.5.6",
|
||||
"next-intl": "^4.4.0",
|
||||
"react": "19.2.0",
|
||||
"react-dom": "19.2.0",
|
||||
"react-hook-form": "^7.66.0",
|
||||
"zod": "^4.1.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/postcss": "^4",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
"eslint": "^9",
|
||||
"eslint-config-next": "^15.5.6",
|
||||
"tailwindcss": "^4",
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
7
postcss.config.mjs
Normal file
7
postcss.config.mjs
Normal file
@@ -0,0 +1,7 @@
|
||||
const config = {
|
||||
plugins: {
|
||||
"@tailwindcss/postcss": {},
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
1
public/file.svg
Normal file
1
public/file.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
|
||||
|
After Width: | Height: | Size: 391 B |
1
public/globe.svg
Normal file
1
public/globe.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
1
public/next.svg
Normal file
1
public/next.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
42
public/robots.txt
Normal file
42
public/robots.txt
Normal file
@@ -0,0 +1,42 @@
|
||||
# robots.txt for Multi-tenant ERP System
|
||||
# Moderate blocking strategy to prevent Chrome warnings
|
||||
|
||||
# Allow homepage and public pages for legitimate access
|
||||
User-agent: *
|
||||
Allow: /
|
||||
Allow: /login
|
||||
Allow: /about
|
||||
|
||||
# Block core ERP functionality and sensitive areas
|
||||
Disallow: /dashboard
|
||||
Disallow: /admin
|
||||
Disallow: /api
|
||||
Disallow: /tenant
|
||||
Disallow: /settings
|
||||
Disallow: /users
|
||||
Disallow: /reports
|
||||
Disallow: /analytics
|
||||
Disallow: /inventory
|
||||
Disallow: /finance
|
||||
Disallow: /hr
|
||||
Disallow: /crm
|
||||
|
||||
# Block common sensitive patterns
|
||||
Disallow: /*?*sessionid=
|
||||
Disallow: /*?*token=
|
||||
Disallow: /*?*key=
|
||||
Disallow: /*/private
|
||||
Disallow: /*/internal
|
||||
|
||||
# Prevent indexing of sensitive file types
|
||||
Disallow: /*.json$
|
||||
Disallow: /*.xml$
|
||||
Disallow: /*.csv$
|
||||
Disallow: /*.xls$
|
||||
Disallow: /*.xlsx$
|
||||
|
||||
# Crawl delay to reduce server load (in seconds)
|
||||
Crawl-delay: 10
|
||||
|
||||
# Sitemap (optional - can be added later)
|
||||
# Sitemap: https://yourdomain.com/sitemap.xml
|
||||
1
public/vercel.svg
Normal file
1
public/vercel.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>
|
||||
|
After Width: | Height: | Size: 128 B |
1
public/window.svg
Normal file
1
public/window.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
|
||||
|
After Width: | Height: | Size: 385 B |
26
src/app/[locale]/globals.css
Normal file
26
src/app/[locale]/globals.css
Normal file
@@ -0,0 +1,26 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
:root {
|
||||
--background: #ffffff;
|
||||
--foreground: #171717;
|
||||
}
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--font-sans: var(--font-geist-sans);
|
||||
--font-mono: var(--font-geist-mono);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--background: #0a0a0a;
|
||||
--foreground: #ededed;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--background);
|
||||
color: var(--foreground);
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
86
src/app/[locale]/layout.tsx
Normal file
86
src/app/[locale]/layout.tsx
Normal file
@@ -0,0 +1,86 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import { NextIntlClientProvider } from 'next-intl';
|
||||
import { getMessages } from 'next-intl/server';
|
||||
import { notFound } from 'next/navigation';
|
||||
import { locales } from '@/i18n/config';
|
||||
import "./globals.css";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: {
|
||||
default: "ERP System - Enterprise Resource Planning",
|
||||
template: "%s | ERP System"
|
||||
},
|
||||
description: "Multi-tenant Enterprise Resource Planning System for SME businesses",
|
||||
robots: {
|
||||
index: false,
|
||||
follow: false,
|
||||
nocache: true,
|
||||
googleBot: {
|
||||
index: false,
|
||||
follow: false,
|
||||
'max-video-preview': -1,
|
||||
'max-image-preview': 'none',
|
||||
'max-snippet': -1,
|
||||
},
|
||||
},
|
||||
verification: {
|
||||
// Add site verification if needed
|
||||
// google: 'your-verification-code',
|
||||
},
|
||||
openGraph: {
|
||||
type: 'website',
|
||||
locale: 'ko_KR',
|
||||
siteName: 'ERP System',
|
||||
title: 'Enterprise Resource Planning System',
|
||||
description: 'Multi-tenant ERP System for SME businesses',
|
||||
},
|
||||
// Prevent caching of sensitive pages
|
||||
other: {
|
||||
'cache-control': 'no-cache, no-store, must-revalidate',
|
||||
},
|
||||
};
|
||||
|
||||
export function generateStaticParams() {
|
||||
return locales.map((locale) => ({ locale }));
|
||||
}
|
||||
|
||||
export default async function RootLayout({
|
||||
children,
|
||||
params,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
params: Promise<{ locale: string }>;
|
||||
}>) {
|
||||
const { locale } = await params;
|
||||
|
||||
// Ensure the incoming locale is valid
|
||||
if (!locales.includes(locale as any)) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
// Providing all messages to the client
|
||||
const messages = await getMessages();
|
||||
|
||||
return (
|
||||
<html lang={locale}>
|
||||
<body
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||
>
|
||||
<NextIntlClientProvider messages={messages}>
|
||||
{children}
|
||||
</NextIntlClientProvider>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
65
src/app/[locale]/page.tsx
Normal file
65
src/app/[locale]/page.tsx
Normal file
@@ -0,0 +1,65 @@
|
||||
import { useTranslations } from 'next-intl';
|
||||
import LanguageSwitcher from '@/components/LanguageSwitcher';
|
||||
import WelcomeMessage from '@/components/WelcomeMessage';
|
||||
import NavigationMenu from '@/components/NavigationMenu';
|
||||
|
||||
/**
|
||||
* Home Page with Internationalization
|
||||
*
|
||||
* Demonstrates i18n implementation in Next.js 16 with next-intl
|
||||
*/
|
||||
export default function Home() {
|
||||
const t = useTranslations('common');
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50 dark:bg-gray-900 p-8">
|
||||
<div className="max-w-6xl mx-auto">
|
||||
{/* Header with Language Switcher */}
|
||||
<header className="flex justify-between items-center mb-8">
|
||||
<h1 className="text-3xl font-bold text-gray-900 dark:text-white">
|
||||
{t('appName')}
|
||||
</h1>
|
||||
<LanguageSwitcher />
|
||||
</header>
|
||||
|
||||
{/* Main Content */}
|
||||
<main className="space-y-8">
|
||||
{/* Welcome Section */}
|
||||
<WelcomeMessage />
|
||||
|
||||
{/* Navigation Menu */}
|
||||
<div>
|
||||
<h2 className="text-xl font-semibold mb-4 text-gray-900 dark:text-white">
|
||||
{t('appName')} Modules
|
||||
</h2>
|
||||
<NavigationMenu />
|
||||
</div>
|
||||
|
||||
{/* Information Section */}
|
||||
<div className="bg-blue-50 dark:bg-blue-900/20 p-6 rounded-lg">
|
||||
<h3 className="text-lg font-semibold mb-2 text-blue-900 dark:text-blue-100">
|
||||
Multi-language Support
|
||||
</h3>
|
||||
<p className="text-blue-800 dark:text-blue-200">
|
||||
This ERP system supports Korean (한국어), English, and Japanese (日本語).
|
||||
Use the language switcher above to change the interface language.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Developer Info */}
|
||||
<div className="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-md">
|
||||
<h3 className="text-lg font-semibold mb-4 text-gray-900 dark:text-white">
|
||||
For Developers
|
||||
</h3>
|
||||
<p className="text-gray-600 dark:text-gray-300 mb-2">
|
||||
Check the documentation in <code className="bg-gray-100 dark:bg-gray-700 px-2 py-1 rounded">claudedocs/i18n-usage-guide.md</code>
|
||||
</p>
|
||||
<p className="text-gray-600 dark:text-gray-300">
|
||||
Message files: <code className="bg-gray-100 dark:bg-gray-700 px-2 py-1 rounded">src/messages/</code>
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
BIN
src/app/favicon.ico
Normal file
BIN
src/app/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
45
src/components/LanguageSwitcher.tsx
Normal file
45
src/components/LanguageSwitcher.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
'use client';
|
||||
|
||||
import { useLocale } from 'next-intl';
|
||||
import { useRouter, usePathname } from 'next/navigation';
|
||||
import { locales, localeNames, localeFlags, type Locale } from '@/i18n/config';
|
||||
|
||||
/**
|
||||
* Language Switcher Component
|
||||
*
|
||||
* Allows users to switch between available locales
|
||||
* Usage: Place in header or navigation bar
|
||||
*/
|
||||
export default function LanguageSwitcher() {
|
||||
const locale = useLocale();
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
|
||||
const handleLocaleChange = (newLocale: Locale) => {
|
||||
// Get the pathname without the current locale
|
||||
const pathnameWithoutLocale = pathname.replace(`/${locale}`, '');
|
||||
|
||||
// Navigate to the new locale
|
||||
router.push(`/${newLocale}${pathnameWithoutLocale}`);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex gap-2">
|
||||
{locales.map((loc) => (
|
||||
<button
|
||||
key={loc}
|
||||
onClick={() => handleLocaleChange(loc)}
|
||||
className={`px-3 py-2 rounded-md text-sm font-medium transition-colors ${
|
||||
locale === loc
|
||||
? 'bg-blue-600 text-white'
|
||||
: 'bg-gray-200 text-gray-700 hover:bg-gray-300 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600'
|
||||
}`}
|
||||
aria-label={`Switch to ${localeNames[loc]}`}
|
||||
>
|
||||
<span className="mr-1">{localeFlags[loc]}</span>
|
||||
{localeNames[loc]}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
43
src/components/NavigationMenu.tsx
Normal file
43
src/components/NavigationMenu.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
'use client';
|
||||
|
||||
import { useTranslations } from 'next-intl';
|
||||
import Link from 'next/link';
|
||||
import { useLocale } from 'next-intl';
|
||||
|
||||
/**
|
||||
* Navigation Menu Component
|
||||
*
|
||||
* Demonstrates translation in navigation elements
|
||||
* Shows how to use translations with dynamic content
|
||||
*/
|
||||
export default function NavigationMenu() {
|
||||
const t = useTranslations('navigation');
|
||||
const locale = useLocale();
|
||||
|
||||
const menuItems = [
|
||||
{ key: 'dashboard', href: '/dashboard' },
|
||||
{ key: 'inventory', href: '/inventory' },
|
||||
{ key: 'finance', href: '/finance' },
|
||||
{ key: 'hr', href: '/hr' },
|
||||
{ key: 'crm', href: '/crm' },
|
||||
{ key: 'reports', href: '/reports' },
|
||||
{ key: 'settings', href: '/settings' },
|
||||
];
|
||||
|
||||
return (
|
||||
<nav className="bg-gray-100 dark:bg-gray-900 p-4 rounded-lg">
|
||||
<ul className="flex flex-wrap gap-4">
|
||||
{menuItems.map((item) => (
|
||||
<li key={item.key}>
|
||||
<Link
|
||||
href={`/${locale}${item.href}`}
|
||||
className="text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300 font-medium"
|
||||
>
|
||||
{t(item.key as any)}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
20
src/components/WelcomeMessage.tsx
Normal file
20
src/components/WelcomeMessage.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
'use client';
|
||||
|
||||
import { useTranslations } from 'next-intl';
|
||||
|
||||
/**
|
||||
* Welcome Message Component
|
||||
*
|
||||
* Demonstrates basic translation usage
|
||||
* Shows how to use useTranslations hook in client components
|
||||
*/
|
||||
export default function WelcomeMessage() {
|
||||
const t = useTranslations('common');
|
||||
|
||||
return (
|
||||
<div className="p-6 bg-white dark:bg-gray-800 rounded-lg shadow-md">
|
||||
<h2 className="text-2xl font-bold mb-2">{t('welcome')}</h2>
|
||||
<p className="text-gray-600 dark:text-gray-300">{t('appName')}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
23
src/i18n/config.ts
Normal file
23
src/i18n/config.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* i18n Configuration for Multi-tenant ERP System
|
||||
*
|
||||
* Supported locales: Korean (ko), English (en), Japanese (ja)
|
||||
* Default locale: Korean (ko)
|
||||
*/
|
||||
|
||||
export const locales = ['ko', 'en', 'ja'] as const;
|
||||
export type Locale = (typeof locales)[number];
|
||||
|
||||
export const defaultLocale: Locale = 'ko';
|
||||
|
||||
export const localeNames: Record<Locale, string> = {
|
||||
ko: '한국어',
|
||||
en: 'English',
|
||||
ja: '日本語',
|
||||
};
|
||||
|
||||
export const localeFlags: Record<Locale, string> = {
|
||||
ko: '🇰🇷',
|
||||
en: '🇺🇸',
|
||||
ja: '🇯🇵',
|
||||
};
|
||||
17
src/i18n/request.ts
Normal file
17
src/i18n/request.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { getRequestConfig } from 'next-intl/server';
|
||||
import { locales } from './config';
|
||||
|
||||
export default getRequestConfig(async ({ requestLocale }) => {
|
||||
// This typically corresponds to the `[locale]` segment
|
||||
let locale = await requestLocale;
|
||||
|
||||
// Ensure that the incoming `locale` is valid
|
||||
if (!locale || !locales.includes(locale as any)) {
|
||||
locale = 'ko'; // fallback to default
|
||||
}
|
||||
|
||||
return {
|
||||
locale,
|
||||
messages: (await import(`@/messages/${locale}.json`)).default,
|
||||
};
|
||||
});
|
||||
165
src/messages/en.json
Normal file
165
src/messages/en.json
Normal file
@@ -0,0 +1,165 @@
|
||||
{
|
||||
"common": {
|
||||
"appName": "ERP System",
|
||||
"welcome": "Welcome",
|
||||
"loading": "Loading...",
|
||||
"save": "Save",
|
||||
"cancel": "Cancel",
|
||||
"delete": "Delete",
|
||||
"edit": "Edit",
|
||||
"search": "Search",
|
||||
"filter": "Filter",
|
||||
"export": "Export",
|
||||
"import": "Import",
|
||||
"refresh": "Refresh",
|
||||
"close": "Close",
|
||||
"confirm": "Confirm",
|
||||
"yes": "Yes",
|
||||
"no": "No",
|
||||
"submit": "Submit",
|
||||
"reset": "Reset",
|
||||
"previous": "Previous",
|
||||
"next": "Next",
|
||||
"selectAll": "Select All",
|
||||
"deselectAll": "Deselect All"
|
||||
},
|
||||
"auth": {
|
||||
"login": "Login",
|
||||
"logout": "Logout",
|
||||
"email": "Email",
|
||||
"password": "Password",
|
||||
"forgotPassword": "Forgot Password?",
|
||||
"rememberMe": "Remember Me",
|
||||
"signIn": "Sign In",
|
||||
"signUp": "Sign Up",
|
||||
"emailPlaceholder": "Enter your email",
|
||||
"passwordPlaceholder": "Enter your password",
|
||||
"loginSuccess": "Login successful",
|
||||
"loginFailed": "Login failed",
|
||||
"invalidCredentials": "Invalid email or password"
|
||||
},
|
||||
"navigation": {
|
||||
"dashboard": "Dashboard",
|
||||
"inventory": "Inventory",
|
||||
"finance": "Finance",
|
||||
"hr": "HR",
|
||||
"crm": "CRM",
|
||||
"reports": "Reports",
|
||||
"settings": "Settings",
|
||||
"admin": "Admin",
|
||||
"profile": "Profile",
|
||||
"help": "Help"
|
||||
},
|
||||
"dashboard": {
|
||||
"title": "Dashboard",
|
||||
"overview": "Overview",
|
||||
"statistics": "Statistics",
|
||||
"recentActivity": "Recent Activity",
|
||||
"quickActions": "Quick Actions",
|
||||
"notifications": "Notifications",
|
||||
"todaysSales": "Today's Sales",
|
||||
"monthlyRevenue": "Monthly Revenue",
|
||||
"activeUsers": "Active Users",
|
||||
"pendingOrders": "Pending Orders"
|
||||
},
|
||||
"inventory": {
|
||||
"title": "Inventory Management",
|
||||
"products": "Products",
|
||||
"categories": "Categories",
|
||||
"suppliers": "Suppliers",
|
||||
"warehouses": "Warehouses",
|
||||
"stockLevel": "Stock Level",
|
||||
"lowStock": "Low Stock",
|
||||
"outOfStock": "Out of Stock",
|
||||
"addProduct": "Add Product",
|
||||
"productName": "Product Name",
|
||||
"sku": "SKU",
|
||||
"quantity": "Quantity",
|
||||
"unitPrice": "Unit Price",
|
||||
"totalValue": "Total Value"
|
||||
},
|
||||
"finance": {
|
||||
"title": "Finance Management",
|
||||
"accounts": "Accounts",
|
||||
"transactions": "Transactions",
|
||||
"invoices": "Invoices",
|
||||
"payments": "Payments",
|
||||
"expenses": "Expenses",
|
||||
"revenue": "Revenue",
|
||||
"profitLoss": "Profit & Loss",
|
||||
"balanceSheet": "Balance Sheet",
|
||||
"cashFlow": "Cash Flow",
|
||||
"budget": "Budget"
|
||||
},
|
||||
"hr": {
|
||||
"title": "HR Management",
|
||||
"employees": "Employees",
|
||||
"departments": "Departments",
|
||||
"attendance": "Attendance",
|
||||
"payroll": "Payroll",
|
||||
"leave": "Leave",
|
||||
"performance": "Performance",
|
||||
"recruitment": "Recruitment",
|
||||
"employeeName": "Employee Name",
|
||||
"position": "Position",
|
||||
"department": "Department",
|
||||
"joinDate": "Join Date",
|
||||
"salary": "Salary"
|
||||
},
|
||||
"crm": {
|
||||
"title": "Customer Relationship Management",
|
||||
"customers": "Customers",
|
||||
"leads": "Leads",
|
||||
"opportunities": "Opportunities",
|
||||
"contacts": "Contacts",
|
||||
"activities": "Activities",
|
||||
"customerName": "Customer Name",
|
||||
"company": "Company",
|
||||
"phone": "Phone",
|
||||
"status": "Status",
|
||||
"lastContact": "Last Contact"
|
||||
},
|
||||
"settings": {
|
||||
"title": "Settings",
|
||||
"general": "General",
|
||||
"profile": "Profile",
|
||||
"security": "Security",
|
||||
"notifications": "Notifications",
|
||||
"language": "Language",
|
||||
"theme": "Theme",
|
||||
"tenant": "Tenant",
|
||||
"users": "Users",
|
||||
"roles": "Roles",
|
||||
"permissions": "Permissions",
|
||||
"billing": "Billing",
|
||||
"integrations": "Integrations"
|
||||
},
|
||||
"errors": {
|
||||
"pageNotFound": "Page Not Found",
|
||||
"serverError": "Server Error Occurred",
|
||||
"unauthorized": "Unauthorized",
|
||||
"forbidden": "Access Forbidden",
|
||||
"badRequest": "Bad Request",
|
||||
"tryAgain": "Please try again",
|
||||
"contactSupport": "Contact support if the problem persists"
|
||||
},
|
||||
"validation": {
|
||||
"required": "This field is required",
|
||||
"invalidEmail": "Please enter a valid email address",
|
||||
"minLength": "Minimum {min} characters required",
|
||||
"maxLength": "Maximum {max} characters allowed",
|
||||
"invalidFormat": "Invalid format",
|
||||
"passwordMismatch": "Passwords do not match"
|
||||
},
|
||||
"messages": {
|
||||
"saveSuccess": "Saved successfully",
|
||||
"saveFailed": "Failed to save",
|
||||
"deleteConfirm": "Are you sure you want to delete?",
|
||||
"deleteSuccess": "Deleted successfully",
|
||||
"deleteFailed": "Failed to delete",
|
||||
"updateSuccess": "Updated successfully",
|
||||
"updateFailed": "Failed to update",
|
||||
"noData": "No data available",
|
||||
"loadingData": "Loading data"
|
||||
}
|
||||
}
|
||||
165
src/messages/ja.json
Normal file
165
src/messages/ja.json
Normal file
@@ -0,0 +1,165 @@
|
||||
{
|
||||
"common": {
|
||||
"appName": "ERPシステム",
|
||||
"welcome": "ようこそ",
|
||||
"loading": "読み込み中...",
|
||||
"save": "保存",
|
||||
"cancel": "キャンセル",
|
||||
"delete": "削除",
|
||||
"edit": "編集",
|
||||
"search": "検索",
|
||||
"filter": "フィルター",
|
||||
"export": "エクスポート",
|
||||
"import": "インポート",
|
||||
"refresh": "更新",
|
||||
"close": "閉じる",
|
||||
"confirm": "確認",
|
||||
"yes": "はい",
|
||||
"no": "いいえ",
|
||||
"submit": "送信",
|
||||
"reset": "リセット",
|
||||
"previous": "前へ",
|
||||
"next": "次へ",
|
||||
"selectAll": "すべて選択",
|
||||
"deselectAll": "すべて解除"
|
||||
},
|
||||
"auth": {
|
||||
"login": "ログイン",
|
||||
"logout": "ログアウト",
|
||||
"email": "メールアドレス",
|
||||
"password": "パスワード",
|
||||
"forgotPassword": "パスワードをお忘れですか?",
|
||||
"rememberMe": "ログイン状態を保持",
|
||||
"signIn": "サインイン",
|
||||
"signUp": "サインアップ",
|
||||
"emailPlaceholder": "メールアドレスを入力してください",
|
||||
"passwordPlaceholder": "パスワードを入力してください",
|
||||
"loginSuccess": "ログインに成功しました",
|
||||
"loginFailed": "ログインに失敗しました",
|
||||
"invalidCredentials": "メールアドレスまたはパスワードが正しくありません"
|
||||
},
|
||||
"navigation": {
|
||||
"dashboard": "ダッシュボード",
|
||||
"inventory": "在庫管理",
|
||||
"finance": "財務管理",
|
||||
"hr": "人事管理",
|
||||
"crm": "顧客管理",
|
||||
"reports": "レポート",
|
||||
"settings": "設定",
|
||||
"admin": "管理者",
|
||||
"profile": "プロフィール",
|
||||
"help": "ヘルプ"
|
||||
},
|
||||
"dashboard": {
|
||||
"title": "ダッシュボード",
|
||||
"overview": "概要",
|
||||
"statistics": "統計",
|
||||
"recentActivity": "最近のアクティビティ",
|
||||
"quickActions": "クイックアクション",
|
||||
"notifications": "通知",
|
||||
"todaysSales": "本日の売上",
|
||||
"monthlyRevenue": "月間収益",
|
||||
"activeUsers": "アクティブユーザー",
|
||||
"pendingOrders": "保留中の注文"
|
||||
},
|
||||
"inventory": {
|
||||
"title": "在庫管理",
|
||||
"products": "製品",
|
||||
"categories": "カテゴリ",
|
||||
"suppliers": "サプライヤー",
|
||||
"warehouses": "倉庫",
|
||||
"stockLevel": "在庫レベル",
|
||||
"lowStock": "在庫不足",
|
||||
"outOfStock": "在庫切れ",
|
||||
"addProduct": "製品を追加",
|
||||
"productName": "製品名",
|
||||
"sku": "SKU",
|
||||
"quantity": "数量",
|
||||
"unitPrice": "単価",
|
||||
"totalValue": "合計金額"
|
||||
},
|
||||
"finance": {
|
||||
"title": "財務管理",
|
||||
"accounts": "アカウント",
|
||||
"transactions": "取引",
|
||||
"invoices": "請求書",
|
||||
"payments": "支払い",
|
||||
"expenses": "経費",
|
||||
"revenue": "収益",
|
||||
"profitLoss": "損益",
|
||||
"balanceSheet": "貸借対照表",
|
||||
"cashFlow": "キャッシュフロー",
|
||||
"budget": "予算"
|
||||
},
|
||||
"hr": {
|
||||
"title": "人事管理",
|
||||
"employees": "従業員",
|
||||
"departments": "部署",
|
||||
"attendance": "出勤",
|
||||
"payroll": "給与",
|
||||
"leave": "休暇",
|
||||
"performance": "パフォーマンス",
|
||||
"recruitment": "採用",
|
||||
"employeeName": "従業員名",
|
||||
"position": "役職",
|
||||
"department": "部署",
|
||||
"joinDate": "入社日",
|
||||
"salary": "給与"
|
||||
},
|
||||
"crm": {
|
||||
"title": "顧客管理",
|
||||
"customers": "顧客",
|
||||
"leads": "リード",
|
||||
"opportunities": "商機",
|
||||
"contacts": "連絡先",
|
||||
"activities": "アクティビティ",
|
||||
"customerName": "顧客名",
|
||||
"company": "会社",
|
||||
"phone": "電話番号",
|
||||
"status": "ステータス",
|
||||
"lastContact": "最終連絡"
|
||||
},
|
||||
"settings": {
|
||||
"title": "設定",
|
||||
"general": "一般",
|
||||
"profile": "プロフィール",
|
||||
"security": "セキュリティ",
|
||||
"notifications": "通知",
|
||||
"language": "言語",
|
||||
"theme": "テーマ",
|
||||
"tenant": "テナント",
|
||||
"users": "ユーザー",
|
||||
"roles": "役割",
|
||||
"permissions": "権限",
|
||||
"billing": "請求",
|
||||
"integrations": "統合"
|
||||
},
|
||||
"errors": {
|
||||
"pageNotFound": "ページが見つかりません",
|
||||
"serverError": "サーバーエラーが発生しました",
|
||||
"unauthorized": "権限がありません",
|
||||
"forbidden": "アクセスが禁止されています",
|
||||
"badRequest": "不正なリクエストです",
|
||||
"tryAgain": "もう一度お試しください",
|
||||
"contactSupport": "問題が解決しない場合はサポートにお問い合わせください"
|
||||
},
|
||||
"validation": {
|
||||
"required": "必須項目です",
|
||||
"invalidEmail": "有効なメールアドレスを入力してください",
|
||||
"minLength": "最低{min}文字以上入力してください",
|
||||
"maxLength": "最大{max}文字まで入力可能です",
|
||||
"invalidFormat": "形式が正しくありません",
|
||||
"passwordMismatch": "パスワードが一致しません"
|
||||
},
|
||||
"messages": {
|
||||
"saveSuccess": "正常に保存されました",
|
||||
"saveFailed": "保存に失敗しました",
|
||||
"deleteConfirm": "本当に削除しますか?",
|
||||
"deleteSuccess": "正常に削除されました",
|
||||
"deleteFailed": "削除に失敗しました",
|
||||
"updateSuccess": "正常に更新されました",
|
||||
"updateFailed": "更新に失敗しました",
|
||||
"noData": "データがありません",
|
||||
"loadingData": "データを読み込んでいます"
|
||||
}
|
||||
}
|
||||
165
src/messages/ko.json
Normal file
165
src/messages/ko.json
Normal file
@@ -0,0 +1,165 @@
|
||||
{
|
||||
"common": {
|
||||
"appName": "ERP 시스템",
|
||||
"welcome": "환영합니다",
|
||||
"loading": "로딩 중...",
|
||||
"save": "저장",
|
||||
"cancel": "취소",
|
||||
"delete": "삭제",
|
||||
"edit": "편집",
|
||||
"search": "검색",
|
||||
"filter": "필터",
|
||||
"export": "내보내기",
|
||||
"import": "가져오기",
|
||||
"refresh": "새로고침",
|
||||
"close": "닫기",
|
||||
"confirm": "확인",
|
||||
"yes": "예",
|
||||
"no": "아니오",
|
||||
"submit": "제출",
|
||||
"reset": "초기화",
|
||||
"previous": "이전",
|
||||
"next": "다음",
|
||||
"selectAll": "전체 선택",
|
||||
"deselectAll": "전체 해제"
|
||||
},
|
||||
"auth": {
|
||||
"login": "로그인",
|
||||
"logout": "로그아웃",
|
||||
"email": "이메일",
|
||||
"password": "비밀번호",
|
||||
"forgotPassword": "비밀번호를 잊으셨나요?",
|
||||
"rememberMe": "로그인 상태 유지",
|
||||
"signIn": "로그인하기",
|
||||
"signUp": "회원가입",
|
||||
"emailPlaceholder": "이메일을 입력하세요",
|
||||
"passwordPlaceholder": "비밀번호를 입력하세요",
|
||||
"loginSuccess": "로그인에 성공했습니다",
|
||||
"loginFailed": "로그인에 실패했습니다",
|
||||
"invalidCredentials": "이메일 또는 비밀번호가 올바르지 않습니다"
|
||||
},
|
||||
"navigation": {
|
||||
"dashboard": "대시보드",
|
||||
"inventory": "재고관리",
|
||||
"finance": "재무관리",
|
||||
"hr": "인사관리",
|
||||
"crm": "고객관리",
|
||||
"reports": "리포트",
|
||||
"settings": "설정",
|
||||
"admin": "관리자",
|
||||
"profile": "프로필",
|
||||
"help": "도움말"
|
||||
},
|
||||
"dashboard": {
|
||||
"title": "대시보드",
|
||||
"overview": "개요",
|
||||
"statistics": "통계",
|
||||
"recentActivity": "최근 활동",
|
||||
"quickActions": "빠른 작업",
|
||||
"notifications": "알림",
|
||||
"todaysSales": "오늘의 매출",
|
||||
"monthlyRevenue": "월간 수익",
|
||||
"activeUsers": "활성 사용자",
|
||||
"pendingOrders": "대기 중인 주문"
|
||||
},
|
||||
"inventory": {
|
||||
"title": "재고 관리",
|
||||
"products": "제품",
|
||||
"categories": "카테고리",
|
||||
"suppliers": "공급업체",
|
||||
"warehouses": "창고",
|
||||
"stockLevel": "재고 수준",
|
||||
"lowStock": "재고 부족",
|
||||
"outOfStock": "품절",
|
||||
"addProduct": "제품 추가",
|
||||
"productName": "제품명",
|
||||
"sku": "SKU",
|
||||
"quantity": "수량",
|
||||
"unitPrice": "단가",
|
||||
"totalValue": "총 가치"
|
||||
},
|
||||
"finance": {
|
||||
"title": "재무 관리",
|
||||
"accounts": "계정",
|
||||
"transactions": "거래",
|
||||
"invoices": "송장",
|
||||
"payments": "결제",
|
||||
"expenses": "비용",
|
||||
"revenue": "수익",
|
||||
"profitLoss": "손익",
|
||||
"balanceSheet": "대차대조표",
|
||||
"cashFlow": "현금 흐름",
|
||||
"budget": "예산"
|
||||
},
|
||||
"hr": {
|
||||
"title": "인사 관리",
|
||||
"employees": "직원",
|
||||
"departments": "부서",
|
||||
"attendance": "출퇴근",
|
||||
"payroll": "급여",
|
||||
"leave": "휴가",
|
||||
"performance": "성과",
|
||||
"recruitment": "채용",
|
||||
"employeeName": "직원명",
|
||||
"position": "직책",
|
||||
"department": "부서",
|
||||
"joinDate": "입사일",
|
||||
"salary": "급여"
|
||||
},
|
||||
"crm": {
|
||||
"title": "고객 관리",
|
||||
"customers": "고객",
|
||||
"leads": "리드",
|
||||
"opportunities": "기회",
|
||||
"contacts": "연락처",
|
||||
"activities": "활동",
|
||||
"customerName": "고객명",
|
||||
"company": "회사",
|
||||
"phone": "전화번호",
|
||||
"status": "상태",
|
||||
"lastContact": "마지막 연락"
|
||||
},
|
||||
"settings": {
|
||||
"title": "설정",
|
||||
"general": "일반",
|
||||
"profile": "프로필",
|
||||
"security": "보안",
|
||||
"notifications": "알림",
|
||||
"language": "언어",
|
||||
"theme": "테마",
|
||||
"tenant": "테넌트",
|
||||
"users": "사용자",
|
||||
"roles": "역할",
|
||||
"permissions": "권한",
|
||||
"billing": "결제",
|
||||
"integrations": "통합"
|
||||
},
|
||||
"errors": {
|
||||
"pageNotFound": "페이지를 찾을 수 없습니다",
|
||||
"serverError": "서버 오류가 발생했습니다",
|
||||
"unauthorized": "권한이 없습니다",
|
||||
"forbidden": "접근이 금지되었습니다",
|
||||
"badRequest": "잘못된 요청입니다",
|
||||
"tryAgain": "다시 시도해주세요",
|
||||
"contactSupport": "문제가 지속되면 고객지원팀에 문의하세요"
|
||||
},
|
||||
"validation": {
|
||||
"required": "필수 항목입니다",
|
||||
"invalidEmail": "유효한 이메일 주소를 입력하세요",
|
||||
"minLength": "최소 {min}자 이상 입력하세요",
|
||||
"maxLength": "최대 {max}자까지 입력 가능합니다",
|
||||
"invalidFormat": "형식이 올바르지 않습니다",
|
||||
"passwordMismatch": "비밀번호가 일치하지 않습니다"
|
||||
},
|
||||
"messages": {
|
||||
"saveSuccess": "성공적으로 저장되었습니다",
|
||||
"saveFailed": "저장에 실패했습니다",
|
||||
"deleteConfirm": "정말 삭제하시겠습니까?",
|
||||
"deleteSuccess": "성공적으로 삭제되었습니다",
|
||||
"deleteFailed": "삭제에 실패했습니다",
|
||||
"updateSuccess": "성공적으로 업데이트되었습니다",
|
||||
"updateFailed": "업데이트에 실패했습니다",
|
||||
"noData": "데이터가 없습니다",
|
||||
"loadingData": "데이터를 불러오는 중입니다"
|
||||
}
|
||||
}
|
||||
182
src/middleware.ts
Normal file
182
src/middleware.ts
Normal file
@@ -0,0 +1,182 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import type { NextRequest } from 'next/server';
|
||||
import createMiddleware from 'next-intl/middleware';
|
||||
import { locales, defaultLocale } from '@/i18n/config';
|
||||
|
||||
/**
|
||||
* Combined Middleware for Multi-tenant ERP System
|
||||
*
|
||||
* Features:
|
||||
* 1. Internationalization (i18n) with locale detection
|
||||
* 2. Bot Detection and blocking for security
|
||||
*
|
||||
* Strategy: Moderate bot blocking
|
||||
* - Allows legitimate browsers and necessary crawlers
|
||||
* - Blocks bots from accessing sensitive ERP areas
|
||||
* - Prevents Chrome security warnings by not being too aggressive
|
||||
*/
|
||||
|
||||
// Create i18n middleware
|
||||
const intlMiddleware = createMiddleware({
|
||||
locales,
|
||||
defaultLocale,
|
||||
localePrefix: 'as-needed', // Don't show default locale in URL
|
||||
});
|
||||
|
||||
// Common bot user-agent patterns (case-insensitive)
|
||||
const BOT_PATTERNS = [
|
||||
/bot/i,
|
||||
/crawler/i,
|
||||
/spider/i,
|
||||
/scraper/i,
|
||||
/curl/i,
|
||||
/wget/i,
|
||||
/python-requests/i,
|
||||
/scrapy/i,
|
||||
/axios/i, // Programmatic access
|
||||
/headless/i,
|
||||
/phantom/i,
|
||||
/selenium/i,
|
||||
/puppeteer/i,
|
||||
/playwright/i, // Browser automation tools
|
||||
/go-http-client/i,
|
||||
/java/i,
|
||||
/okhttp/i,
|
||||
/apache-httpclient/i,
|
||||
];
|
||||
|
||||
// Paths that should be protected from bots
|
||||
const PROTECTED_PATHS = [
|
||||
'/dashboard',
|
||||
'/admin',
|
||||
'/api',
|
||||
'/tenant',
|
||||
'/settings',
|
||||
'/users',
|
||||
'/reports',
|
||||
'/analytics',
|
||||
'/inventory',
|
||||
'/finance',
|
||||
'/hr',
|
||||
'/crm',
|
||||
'/employee',
|
||||
'/customer',
|
||||
'/supplier',
|
||||
'/orders',
|
||||
'/invoices',
|
||||
'/payroll',
|
||||
];
|
||||
|
||||
// Paths that are allowed for everyone (including bots)
|
||||
const PUBLIC_PATHS = [
|
||||
'/',
|
||||
'/login',
|
||||
'/about',
|
||||
'/contact',
|
||||
'/robots.txt',
|
||||
'/sitemap.xml',
|
||||
'/favicon.ico',
|
||||
];
|
||||
|
||||
/**
|
||||
* Check if user-agent matches known bot patterns
|
||||
*/
|
||||
function isBot(userAgent: string): boolean {
|
||||
if (!userAgent) return false;
|
||||
|
||||
return BOT_PATTERNS.some(pattern => pattern.test(userAgent));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the path should be protected from bots
|
||||
*/
|
||||
function isProtectedPath(pathname: string): boolean {
|
||||
return PROTECTED_PATHS.some(path => pathname.startsWith(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the path is public and accessible to all
|
||||
*/
|
||||
function isPublicPath(pathname: string): boolean {
|
||||
return PUBLIC_PATHS.some(path => pathname === path || pathname.startsWith(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove locale prefix from pathname for bot checking
|
||||
*/
|
||||
function getPathnameWithoutLocale(pathname: string): string {
|
||||
for (const locale of locales) {
|
||||
if (pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`) {
|
||||
return pathname.slice(`/${locale}`.length) || '/';
|
||||
}
|
||||
}
|
||||
return pathname;
|
||||
}
|
||||
|
||||
export function middleware(request: NextRequest) {
|
||||
const { pathname } = request.nextUrl;
|
||||
const userAgent = request.headers.get('user-agent') || '';
|
||||
|
||||
// Remove locale prefix for path checking
|
||||
const pathnameWithoutLocale = getPathnameWithoutLocale(pathname);
|
||||
|
||||
// Check if request is from a bot
|
||||
const isBotRequest = isBot(userAgent);
|
||||
|
||||
// Block bots from protected paths (check both with and without locale)
|
||||
if (isBotRequest && (isProtectedPath(pathname) || isProtectedPath(pathnameWithoutLocale))) {
|
||||
console.log(`[Bot Blocked] ${userAgent} attempted to access ${pathname}`);
|
||||
|
||||
// Return 403 Forbidden with appropriate message
|
||||
return new NextResponse(
|
||||
JSON.stringify({
|
||||
error: 'Access Denied',
|
||||
message: 'Automated access to this resource is not permitted.',
|
||||
code: 'BOT_ACCESS_DENIED'
|
||||
}),
|
||||
{
|
||||
status: 403,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Robots-Tag': 'noindex, nofollow, noarchive, nosnippet',
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Run i18n middleware for locale detection and routing
|
||||
const intlResponse = intlMiddleware(request);
|
||||
|
||||
// Add security headers to the response
|
||||
intlResponse.headers.set('X-Robots-Tag', 'noindex, nofollow, noarchive, nosnippet');
|
||||
intlResponse.headers.set('X-Content-Type-Options', 'nosniff');
|
||||
intlResponse.headers.set('X-Frame-Options', 'DENY');
|
||||
intlResponse.headers.set('Referrer-Policy', 'strict-origin-when-cross-origin');
|
||||
|
||||
// Log bot access attempts (for monitoring)
|
||||
if (isBotRequest) {
|
||||
console.log(`[Bot Allowed] ${userAgent} accessed ${pathname}`);
|
||||
}
|
||||
|
||||
return intlResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure which paths the middleware should run on
|
||||
*
|
||||
* Matcher configuration:
|
||||
* - Excludes static files and assets
|
||||
* - Includes all app routes
|
||||
*/
|
||||
export const config = {
|
||||
matcher: [
|
||||
/*
|
||||
* Match all request paths except:
|
||||
* - _next/static (static files)
|
||||
* - _next/image (image optimization files)
|
||||
* - favicon.ico (favicon file)
|
||||
* - public files (images, etc.)
|
||||
*/
|
||||
'/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico)$).*)',
|
||||
],
|
||||
};
|
||||
42
tsconfig.json
Normal file
42
tsconfig.json
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2017",
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"./src/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
".next/types/**/*.ts",
|
||||
".next/dev/types/**/*.ts",
|
||||
"**/*.mts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user