Skip to content

Commit

Permalink
convert with-axiom to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
schehata committed Jul 7, 2022
1 parent c1a85e7 commit 0705302
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
9 changes: 0 additions & 9 deletions examples/with-axiom/middleware.js

This file was deleted.

9 changes: 9 additions & 0 deletions 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)
6 changes: 6 additions & 0 deletions examples/with-axiom/package.json
Expand Up @@ -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"
}
}
@@ -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 <Component {...pageProps} />
}

Expand Down
@@ -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' })
}
Expand Down
@@ -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 <div>Failed to load</div>
Expand All @@ -26,3 +27,5 @@ export default function Home() {
</div>
)
}

export default Home

0 comments on commit 0705302

Please sign in to comment.