Skip to content

Commit

Permalink
Break into middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
cesalberca committed Jul 16, 2024
1 parent ee9f3df commit 4246197
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 35 deletions.
8 changes: 8 additions & 0 deletions src/app/[locale]/about.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { NextPage } from 'next'
import { AboutPage } from '../../features/about/delivery/about.page'

const Index: NextPage = () => {
return <AboutPage />
}

export default Index
File renamed without changes.
17 changes: 0 additions & 17 deletions src/app/about.tsx

This file was deleted.

3 changes: 2 additions & 1 deletion src/app/components/posts.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Link from 'next/link'
import { getBlogPosts } from '../utils'
import type { FC } from 'react'

export function BlogPosts() {
export const BlogPosts: FC = () => {
let allBlogs = getBlogPosts()

return (
Expand Down
10 changes: 1 addition & 9 deletions src/app/links.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import type { GetStaticProps, NextPage } from 'next'
import type { NextPage } from 'next'
import { LinksPage } from '../features/links/delivery/links.page'

const Index: NextPage = () => {
return <LinksPage />
}

export const getStaticProps: GetStaticProps = async ({ locale }) => {
return {
props: {
messages: (await import(`../core/i18n/${locale}.json`)).default,
},
}
}

export default Index
5 changes: 3 additions & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HomePage } from '../features/home/ui/home.page'
import { BlogPosts } from './components/posts'
import { useTranslations } from 'next-intl'

export default function Home() {
return <BlogPosts />
const t = useTranslations()
return <h1>{t('common.coverage')}</h1>
}
2 changes: 1 addition & 1 deletion src/core/i18n/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export default getRequestConfig(async ({ locale }) => {
if (!locales.includes(locale as any)) notFound()

return {
messages: (await import(`../translations/${locale}.json`)).default,
messages: (await import(`./translations/${locale}.json`)).default,
}
})
6 changes: 1 addition & 5 deletions src/app/middleware/middleware.ts → src/i18n.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import createMiddleware from 'next-intl/middleware'

export default createMiddleware({
// A list of all locales that are supported
export const i18nMiddleware = createMiddleware({
locales: ['en', 'de'],

// Used when no locale matches
defaultLocale: 'en',
})

export const config = {
// Match only internationalized pathnames
matcher: ['/', '/(en|es)/:path*'],
}
1 change: 1 addition & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { i18nMiddleware as default, config } from './i18n.middleware'

0 comments on commit 4246197

Please sign in to comment.