Skip to content

Instantly share code, notes, and snippets.

View sand97's full-sized avatar

Bruce Guenkam sand97

View GitHub Profile
@sand97
sand97 / link_shame.js
Last active January 7, 2022 08:40
Link nextjs
@sand97
sand97 / link_exemple.js
Last active January 7, 2022 08:41
Nextjs Link exampple
@sand97
sand97 / product.js
Created January 7, 2022 08:35
nextjs get server side props example
const Product = (props) => {
return <div>
{ props.data.map(p => <div key={p.id}>{p.name}</div>) }
</div>
}
export const getServerSideProps = async (context) => {
const {name} = context.query
//you can fetch data from your api like this
// const res = await
@sand97
sand97 / cats-fact.js
Created January 3, 2022 00:51
Next.js static file optimization
import { useRouter } from 'next/router'
import Head from 'next/head'
export default function Fact({ fact }) {
const router = useRouter()
return (
<div style={{ textAlign: 'center' }}>
<h1>A fact about cat</h1>
<br/>
<p>{fact}</p>
@sand97
sand97 / gist:ad66d3573a3a1ad5e3a1ec0473db50ee
Created January 3, 2022 00:28
Package.json script for custom server of Next.js application
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
}
@sand97
sand97 / server.js
Last active January 3, 2022 00:31
Custom Next.js server.js with purge cache handler.
// server.js
const { createServer } = require('http');
const next = require('next');
const { promises, existsSync } = require('fs');
const dev = (process.env.NODE_ENV || '').indexOf('production') === -1;
const app = next({ dev });
const handle = app.getRequestHandler();