This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"zzz":"","a2":24,"5":"BUI Technologies","0":19,"1":[{"t":{"a":[{"b":1016,"a":0}],"b":0},"b":{"a":[{"a":680,"b":1016}],"b":0},"d":{"b":0,"a":[{"a":340,"b":1016}]},"e":{"a":[{"b":1016,"a":140}],"b":0},"d0":23,"4":"MaterialIcons-Regular","c":{"a":[{"a":306,"b":1016}],"b":0},"z":"4","f":"uicol_systemCyan-100","3":""},{"e":{"b":0,"a":[{"b":1016,"a":140}]},"t":{"b":0,"a":[{"b":1016,"a":0}]},"d0":20,"c":{"a":[{"b":1016,"a":666}],"b":0},"b":{"a":[{"b":1016,"a":700}],"b":0},"d":{"a":[{"b":1016,"a":340}],"b":0},"4":"MaterialIcons-Regular","z":"4","3":"","f":"uicol_systemCyan-100"},{"c":{"b":0,"a":[{"a":486,"b":1016}]},"z":"4","3":"VPN 5","b":{"b":0,"a":[{"a":700,"b":1016}]},"f":"uicol_systemCyan-100","t":{"a":[{"a":0,"b":1016}],"b":0},"4":"ss_","d":{"b":0,"a":[{"b":1016,"a":340}]},"e":{"a":[{"a":140,"b":1016}],"b":0},"d0":19},{"t":{"b":0,"a":[{"a":0,"b":1224}]},"d":{"a":[{"a":720,"b":1224}],"b":0},"1":"System Semi Bold","66":[{"6":"Endpoint","19":"GET","18":"https:\/\/YOURENDPOINT.deno.dev\/","5":"JSON Endpoint","23 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { serve } from "https://deno.land/std@0.155.0/http/server.ts"; | |
serve(async (req: Request) => { | |
const data = await fetch(`https://www.beeminder.com/api/v1/users/${Deno.env.get('username')}/goals.json?auth_token=${Deno.env.get('token')}`).then(d => d.json()); | |
let goals = ""; | |
let load = 0; | |
let productivityScore = 0; | |
data.forEach((curr) => { | |
const urgencyLoad = Math.max(0, 7 - curr.safebuf); | |
const productivity = Math.min(curr.safebuf, 7); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { pathname, origin, locale, search, protocol } = request.nextUrl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// const { pathname } = request.nextUrl; | |
function isPage(pathname: string): boolean { | |
return !(pathname.includes('.') || pathname.startsWith('/api') || pathname.includes('_next')); | |
} | |
// and consequently, you can work out how to identify a file a or an API route with this snippet! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const config = { | |
matcher: ['/about/:path*', '/dashboard/:path*'], | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function middleware(request: NextRequest) { | |
const response = NextResponse.next(); | |
for await (const middlewareFunction of MIDDLEWARES) { | |
const middlewareResponse = await middlewareFunction(request, response); | |
if (isRedirecting(middlewareResponse)) { | |
return middlewareResponse; | |
} | |
if (isRewriting(middlewareResponse)) { | |
return middlewareResponse; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NextResponse } from 'next/server'; | |
import type { NextRequest } from 'next/server'; | |
import { anotherMiddleware } from './middlewares/anotherMiddleware'; | |
import { someMiddleware } from './middlewares/someMiddleware'; | |
type middlewareFunction = (request: NextRequest, response: NextResponse) => NextResponse | Promise<NextResponse>; | |
const MIDDLEWARES: middlewareFunction[] = [someMiddleware, anotherMiddleware]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// works, get replaced in build time | |
const someVar = process.env.MY_VARIABLE; | |
// doesn't work! How should Next know how to replace it in build time? | |
function getVariable(name) { | |
return process.env[name]; | |
} | |
const someVar = getVariable(MY_VARIABLE); | |
// try this! | |
console.log(process.env); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const handler: NextApiHandler = (request: NextApiRequest, response: NextApiResponse) => { | |
MyModule.log('sending a request'); // yup, no worries | |
axios.get('http://myservice.com'); // fine, why not! | |
return response.status(200).json({ ok: true }); | |
}; | |
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { origin } = request.nextUrl.clone(); | |
fetch(origin + '/api/myAPI', { | |
... | |
}); |
NewerOlder