diff --git a/examples/with-axiom/middleware.js b/examples/with-axiom/middleware.js deleted file mode 100644 index 9ff1b31aab37..000000000000 --- a/examples/with-axiom/middleware.js +++ /dev/null @@ -1,9 +0,0 @@ -import { NextResponse } from 'next/server' -import { log, withAxiom } from 'next-axiom' - -async function middleware(_req, ev) { - log.info("Hello from middleware", { 'bar': 'baz' }); - return NextResponse.next() -} - -export default withAxiom(middleware) \ No newline at end of file diff --git a/examples/with-axiom/middleware.ts b/examples/with-axiom/middleware.ts new file mode 100644 index 000000000000..415b117e4fdf --- /dev/null +++ b/examples/with-axiom/middleware.ts @@ -0,0 +1,9 @@ +import { NextResponse, NextRequest } from 'next/server' +import { log, withAxiom } from 'next-axiom' + +async function middleware(_req: NextRequest) { + log.info("Hello from middleware", { 'bar': 'baz' }) + return NextResponse.next() +} + +export default withAxiom(middleware) diff --git a/examples/with-axiom/package.json b/examples/with-axiom/package.json index 9be5078a7e5e..f68957eb498a 100644 --- a/examples/with-axiom/package.json +++ b/examples/with-axiom/package.json @@ -11,5 +11,11 @@ "react": "^18.0.0", "react-dom": "^18.0.0", "swr": "^1.3.0" + }, + "devDependencies": { + "@types/react": "^18.0.5", + "@types/react-dom": "^18.0.1", + "@types/node": "^16.11.26", + "typescript": "^4.6.3" } } \ No newline at end of file diff --git a/examples/with-axiom/pages/_app.js b/examples/with-axiom/pages/_app.tsx similarity index 63% rename from examples/with-axiom/pages/_app.js rename to examples/with-axiom/pages/_app.tsx index 2cae5cb85614..11ce65c35bdb 100644 --- a/examples/with-axiom/pages/_app.js +++ b/examples/with-axiom/pages/_app.tsx @@ -1,10 +1,12 @@ import { log } from 'next-axiom' - +import { AppProps } from 'next/app' export { reportWebVitals } from 'next-axiom' log.info('Hello from frontend', { foo: 'bar' }) -function MyApp({ Component, pageProps }) { +type props = {} + +const MyApp = ({ Component, pageProps }: AppProps) => { return } diff --git a/examples/with-axiom/pages/api/hello.js b/examples/with-axiom/pages/api/hello.ts similarity index 55% rename from examples/with-axiom/pages/api/hello.js rename to examples/with-axiom/pages/api/hello.ts index ab84f1479a28..8e3e71efc832 100644 --- a/examples/with-axiom/pages/api/hello.js +++ b/examples/with-axiom/pages/api/hello.ts @@ -1,7 +1,8 @@ // Next.js API route support: https://nextjs.org/docs/api-routes/introduction -import { log, withAxiom } from 'next-axiom' +import type { NextApiRequest, NextApiResponse } from 'next' +import { log, withAxiom } from 'next-axiom'; -async function handler(req, res) { +async function handler(req: NextApiRequest, res: NextApiResponse) { log.info('Hello from function', { url: req.url }); res.status(200).json({ name: 'John Doe' }) } diff --git a/examples/with-axiom/pages/index.js b/examples/with-axiom/pages/index.tsx similarity index 56% rename from examples/with-axiom/pages/index.js rename to examples/with-axiom/pages/index.tsx index 3deccad91552..8c7cfec4c098 100644 --- a/examples/with-axiom/pages/index.js +++ b/examples/with-axiom/pages/index.tsx @@ -1,20 +1,21 @@ +import { GetStaticPropsContext } from 'next' import { log } from 'next-axiom' import useSWR from 'swr' -export async function getStaticProps(context) { - log.info('Hello from SSR', { context }) +export const getStaticProps = async (ctx: GetStaticPropsContext) => { + log.info('Hello from SSR', { ctx }) return { props: {}, } } -const fetcher = async (...args) => { +const fetcher = async (...args: any[]) => { log.info('Hello from SWR', { args }); - const res = await fetch(...args); + const res = await fetch.apply(null, [...args]); return await res.json(); } -export default function Home() { +const Home = () => { const { data, error } = useSWR('/api/hello', fetcher) if (error) return
Failed to load
@@ -26,3 +27,5 @@ export default function Home() { ) } + +export default Home