feat: upgrade to app directory

This commit is contained in:
Bart Stefanski 2023-11-25 23:30:41 +01:00
parent fb4a7cda23
commit 38fc128d62
10 changed files with 61 additions and 68 deletions

3
app/api/health/route.ts Normal file
View file

@ -0,0 +1,3 @@
export async function GET() {
return Response.json({ status: "ok" })
}

9
app/layout.tsx Normal file
View file

@ -0,0 +1,9 @@
import "styles/tailwind.css"
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}

View file

@ -1,7 +1,7 @@
import { GetServerSidePropsContext } from "next"
import Head from "next/head"
import { Button } from "components/Button/Button"
import { LP_GRID_ITEMS } from "../lp-items"
import { LP_GRID_ITEMS } from "lp-items"
export default function Web() {
return (
@ -59,17 +59,3 @@ export default function Web() {
)
}
export async function getServerSideProps({ req, res }: GetServerSidePropsContext) {
if (req.headers?.host?.includes("next-enterprise.vercel.app")) {
return {
redirect: {
destination: "https://blazity.com/open-source/nextjs-enterprise-boilerplate",
permanent: true,
},
}
}
return {
props: {},
}
}

22
middleware.ts Normal file
View file

@ -0,0 +1,22 @@
import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"
export function middleware(request: NextRequest) {
// TODO: Feel free to remove this block
if (request.headers?.get("host")?.includes("next-enterprise.vercel.app")) {
return NextResponse.redirect("https://blazity.com/open-source/nextjs-enterprise-boilerplate", { status: 301 })
}
}
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
*/
"/((?!api|_next/static|_next/image|favicon.ico).*)",
],
}

View file

@ -79,6 +79,7 @@
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.1.2",
"@total-typescript/ts-reset": "^0.5.1",
"@types/jest": "^29.5.10",
"@types/node": "^20.10.0",
"@types/react": "^18.2.38",
"@types/react-dom": "^18.2.17",
@ -102,7 +103,7 @@
"patch-package": "^8.0.0",
"postcss": "^8.4.31",
"postinstall-postinstall": "^2.1.0",
"prettier": "^3.1.0",
"prettier": "3.0.3",
"prettier-plugin-tailwindcss": "^0.5.7",
"semantic-release": "^22.0.8",
"storybook": "^7.5.3",

View file

@ -1,29 +0,0 @@
import { render } from "@testing-library/react"
import { AppProps } from "next/app"
import MyApp from "./_app"
// Mock router object with required properties
const router = {
basePath: "",
pathname: "/",
query: {},
asPath: "/",
}
describe("MyApp", () => {
it("should render a component with page props", () => {
const props: AppProps = {
Component: ({ title }) => (
<>
<div>Test Component</div>
<div>{title}</div>
</>
),
pageProps: { title: "Test Page" },
router: router as never, // Include mocked router object in props
}
const { getByText } = render(<MyApp {...props} />)
expect(getByText("Test Component")).toBeInTheDocument()
expect(getByText("Test Page")).toBeInTheDocument()
})
})

View file

@ -1,9 +0,0 @@
import "../styles/tailwind.css"
import { AppProps } from "next/app"
function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
export default MyApp

View file

@ -1,5 +0,0 @@
import { NextApiRequest, NextApiResponse } from "next"
export default function handler(req: NextApiRequest, res: NextApiResponse) {
res.status(200).json({ status: "ok" })
}

View file

@ -7,6 +7,7 @@
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noUncheckedIndexedAccess": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
@ -16,8 +17,14 @@
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"baseUrl": "."
"baseUrl": ".",
"types": ["node", "jest", "@testing-library/jest-dom"],
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.mjs", "jest.config.js"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.mjs", "jest.config.js", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}

View file

@ -4974,6 +4974,14 @@
dependencies:
"@types/istanbul-lib-report" "*"
"@types/jest@^29.5.10":
version "29.5.10"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-29.5.10.tgz#a10fc5bab9e426081c12b2ef73d24d4f0c9b7f50"
integrity sha512-tE4yxKEphEyxj9s4inideLHktW/x6DwesIwWZ9NN1FKf9zbJYsnhBoA9vrHA/IuIOKwPa5PcFBNV4lpMIOEzyQ==
dependencies:
expect "^29.0.0"
pretty-format "^29.0.0"
"@types/jsdom@^20.0.0":
version "20.0.1"
resolved "https://registry.yarnpkg.com/@types/jsdom/-/jsdom-20.0.1.tgz#07c14bc19bd2f918c1929541cdaacae894744808"
@ -8576,7 +8584,7 @@ expect-playwright@^0.8.0:
resolved "https://registry.yarnpkg.com/expect-playwright/-/expect-playwright-0.8.0.tgz#6d4ebe0bdbdd3c1693d880d97153b96a129ae4e8"
integrity sha512-+kn8561vHAY+dt+0gMqqj1oY+g5xWrsuGMk4QGxotT2WS545nVqqjs37z6hrYfIuucwqthzwJfCJUEYqixyljg==
expect@^29.7.0:
expect@^29.0.0, expect@^29.7.0:
version "29.7.0"
resolved "https://registry.yarnpkg.com/expect/-/expect-29.7.0.tgz#578874590dcb3214514084c08115d8aee61e11bc"
integrity sha512-2Zks0hf1VLFYI1kbh0I5jP3KHHyCHpkfyHBzsSXRFgl/Bg9mWYfMW8oD+PdMPlEwy5HNsR9JutYy6pMeOh61nw==
@ -13108,16 +13116,16 @@ prettier-plugin-tailwindcss@^0.5.7:
resolved "https://registry.yarnpkg.com/prettier-plugin-tailwindcss/-/prettier-plugin-tailwindcss-0.5.7.tgz#d05dc42c6f2167e3bf2c20e9f71a1fff4232b5d9"
integrity sha512-4v6uESAgwCni6YF6DwJlRaDjg9Z+al5zM4JfngcazMy4WEf/XkPS5TEQjbD+DZ5iNuG6RrKQLa/HuX2SYzC3kQ==
prettier@3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.0.3.tgz#432a51f7ba422d1469096c0fdc28e235db8f9643"
integrity sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==
prettier@^2, prettier@^2.8.0:
version "2.8.8"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
prettier@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.1.0.tgz#c6d16474a5f764ea1a4a373c593b779697744d5e"
integrity sha512-TQLvXjq5IAibjh8EpBIkNKxO749UEWABoiIZehEPiY4GNpVdhaFKqSTu+QrlU6D2dPAfubRmtJTi4K4YkQ5eXw==
pretty-error@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/pretty-error/-/pretty-error-4.0.0.tgz#90a703f46dd7234adb46d0f84823e9d1cb8f10d6"
@ -13135,7 +13143,7 @@ pretty-format@^27.0.2:
ansi-styles "^5.0.0"
react-is "^17.0.1"
pretty-format@^29.7.0:
pretty-format@^29.0.0, pretty-format@^29.7.0:
version "29.7.0"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-29.7.0.tgz#ca42c758310f365bfa71a0bda0a807160b776812"
integrity sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==