Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Tamás Tárnok trnktms

:octocat:
View GitHub Profile
View CustomContentResolver.cs
public class CustomContentsResolver : RenderingContentsResolver
{
private readonly HttpContextBase _httpContext;
public CustomContentsResolver(HttpContextBase httpContext)
{
_httpContext = httpContext;
}
protected override JObject ProcessItem(Item item, Rendering rendering, IRenderingConfiguration renderingConfig)
View layout-service-factory.ts
import { LayoutService } from '@sitecore-jss/sitecore-jss-nextjs';
import config from 'temp/config';
import { ParameterizedRestLayoutService } from './parameterized-rest-layout-service';
export class LayoutServiceFactory {
create(): LayoutService {
return new ParameterizedRestLayoutService({
apiHost: config.sitecoreApiHost as string,
apiKey: config.sitecoreApiKey,
View parameterized-rest-layout-service.ts
import { RestLayoutService, RestLayoutServiceConfig } from '@sitecore-jss/sitecore-jss-nextjs';
interface FetchParams {
[param: string]: string | number | boolean;
sc_apikey: string;
sc_site: string;
sc_lang: string;
tracking: boolean;
}
View next.config.js
async rewrites() {
// When in connected mode we want to proxy Sitecore paths off to Sitecore
return [
// media items
{
source: '/-/:path*',
destination: '/api/rewrite-sitecore-media',
}
];
}
View next.config.js
async rewrites() {
// When in connected mode we want to proxy Sitecore paths off to Sitecore
return [
// media items
{
source: '/-/:path*',
destination: `${jssConfig.sitecoreApiHost}/-/:path*`,
}
];
}
View index.ts
import axios from 'axios';
import { NextApiRequest, NextApiResponse } from 'next';
/**
* Custom API implementation for rewrites to support runtime rewrite config
* https://github.com/vercel/next.js/issues/21888
*/
export const handler = async (req: NextApiRequest, res: NextApiResponse): Promise<void> => {
const newPath = req.url as string;
if (newPath) {
View Products.tsx
import { AppContext } from '@/pages/[[...path]]';
import { Box } from '@mui/material';
import { useContext } from 'react';
export const Products = (): JSX.Element => {
const { products: contextProducts } = useContext(AppContext);
return (<Box>{contextProducts?.map(p => p.Name).concat()}</Box>);
};
export default Products;
View [[...path]].tsx
import { ComponentPropsContext, handleEditorFastRefresh, SitecoreContext } from '@sitecore-jss/sitecore-jss-nextjs';
import { GetServerSideProps } from 'next';
import { getSession } from 'next-auth/react';
import { createContext, useEffect } from 'react';
import Layout from 'src/Layout';
import NotFound from 'src/NotFound';
import { componentFactory } from 'temp/componentFactory';
import { Product } from '@/interfaces/product';
import { Country } from '@/interfaces/address';
import { GetReservationsResponse } from '@/interfaces/booking';
View redis-client.ts
import { createClient } from 'redis';
class RedisClient {
private static redisClient: ReturnType<typeof createClient>;
private static initRedisClient() {
const redisClient = createClient({
url: process.env.REDIS_URL,
password: process.env.REDIS_PASSWORD,
socket: {
View services.ts
import { ComponentRendering, LayoutServicePageState } from '@sitecore-jss/sitecore-jss-nextjs';
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
import { ParsedUrlQuery } from 'querystring';
import { User } from '@/interfaces/user';
import { mergeAxiosResponseArrays } from '@/lib/helpers';
import RedisClient from '@/lib/redis-client';
import { StyleguideSitecoreContextValue } from './component-props';
interface Service {
[key: string]: {