diff --git a/packages/create-sitecore-jss/src/templates/nextjs/src/lib/middleware/plugins/redirects.ts b/packages/create-sitecore-jss/src/templates/nextjs/src/lib/middleware/plugins/redirects.ts index cf592b86d9..b9db64ce3d 100644 --- a/packages/create-sitecore-jss/src/templates/nextjs/src/lib/middleware/plugins/redirects.ts +++ b/packages/create-sitecore-jss/src/templates/nextjs/src/lib/middleware/plugins/redirects.ts @@ -1,11 +1,13 @@ import { NextRequest, NextResponse } from 'next/server'; -import { RedirectType, GraphQLRedirectsService } from '@sitecore-jss/sitecore-jss-nextjs'; +import { + RedirectType, + GraphQLRedirectsService, + REDIRECT_TYPE_PREFIX, + REDIRECT_TYPE_DEFAULT, +} from '@sitecore-jss/sitecore-jss-nextjs'; import config from 'temp/config'; import { MiddlewarePlugin } from '..'; -const REDIRECT_TYPE_PREFIX = 'REDIRECT_'; -const REDIRECT_TYPE_DEFAULT = 301; - class RedirectsPlugin implements MiddlewarePlugin { private redirectsService: GraphQLRedirectsService; order = 0; diff --git a/packages/sitecore-jss-nextjs/src/index.ts b/packages/sitecore-jss-nextjs/src/index.ts index 1ef19d9a0a..57c9472906 100644 --- a/packages/sitecore-jss-nextjs/src/index.ts +++ b/packages/sitecore-jss-nextjs/src/index.ts @@ -59,6 +59,8 @@ export { RedirectsQueryResult, GraphQLRedirectsService, GraphQLRedirectsServiceConfig, + REDIRECT_TYPE_PREFIX, + REDIRECT_TYPE_DEFAULT, } from '@sitecore-jss/sitecore-jss/site'; export { GraphQLRequestClient } from '@sitecore-jss/sitecore-jss'; diff --git a/packages/sitecore-jss/src/site/graphql-redirect-service.test.ts b/packages/sitecore-jss/src/site/graphql-redirect-service.test.ts index 583e9e0191..4f31f81517 100644 --- a/packages/sitecore-jss/src/site/graphql-redirect-service.test.ts +++ b/packages/sitecore-jss/src/site/graphql-redirect-service.test.ts @@ -37,7 +37,7 @@ describe('GraphQLRedirectsService', () => { nock.cleanAll(); }); - const mockRobotsRequest = (siteName?: string) => { + const mockRedirectsRequest = (siteName?: string) => { nock(endpoint) .post('/') .reply( @@ -54,7 +54,7 @@ describe('GraphQLRedirectsService', () => { describe('fetch redirects from site by graphql', () => { it('should get error if redirects has empty siteName', async () => { - mockRobotsRequest(); + mockRedirectsRequest(); const service = new GraphQLRedirectsService({ endpoint, apiKey, siteName: '' }); await service.fetchRedirects().catch((error: Error) => { @@ -65,7 +65,7 @@ describe('GraphQLRedirectsService', () => { }); it('should get redirects', async () => { - mockRobotsRequest(siteName); + mockRedirectsRequest(siteName); const service = new GraphQLRedirectsService({ endpoint, apiKey, siteName }); const result = await service.fetchRedirects(); @@ -76,7 +76,7 @@ describe('GraphQLRedirectsService', () => { }); it('should get no redirects', async () => { - mockRobotsRequest(); + mockRedirectsRequest(); const service = new GraphQLRedirectsService({ endpoint, apiKey, siteName }); const result = await service.fetchRedirects(); diff --git a/packages/sitecore-jss/src/site/graphql-redirects-service.ts b/packages/sitecore-jss/src/site/graphql-redirects-service.ts index 79f1f02bc6..2d45ab63c1 100644 --- a/packages/sitecore-jss/src/site/graphql-redirects-service.ts +++ b/packages/sitecore-jss/src/site/graphql-redirects-service.ts @@ -1,7 +1,8 @@ import { GraphQLClient, GraphQLRequestClient } from '../graphql'; import debug from '../debug'; -export const PREFIX_REDIRECT_TYPE = 'REDIRECT_'; +export const REDIRECT_TYPE_PREFIX = 'REDIRECT_'; +export const REDIRECT_TYPE_DEFAULT = 301; export type RedirectType = { pattern: string; diff --git a/packages/sitecore-jss/src/site/index.ts b/packages/sitecore-jss/src/site/index.ts index 8c51a95533..0f08fd0532 100644 --- a/packages/sitecore-jss/src/site/index.ts +++ b/packages/sitecore-jss/src/site/index.ts @@ -6,6 +6,8 @@ export { export { RedirectType, RedirectsQueryResult, + REDIRECT_TYPE_PREFIX, + REDIRECT_TYPE_DEFAULT, GraphQLRedirectsService, GraphQLRedirectsServiceConfig, } from './graphql-redirects-service';