Skip to content

Commit

Permalink
[Chore] Remove deprecations - update sxa (#1781)
Browse files Browse the repository at this point in the history
  • Loading branch information
art-alexeyenko authored Apr 23, 2024
1 parent 0d84c70 commit d9175e0
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 54 deletions.
36 changes: 36 additions & 0 deletions docs/upgrades/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,42 @@ Most of this re-iterates the instructions already provided in 21.6 and 21.7 upgr
* Update RedirectsMiddleware at `/src/lib/middleware/plugins/redirects.ts` to use clientFactory if it wasn't as part of ([JSS 21.6 upgrade guide](https://doc.sitecore.com/xmc/en/developers/jss/217/jss-xmc/upgrade-jss-21-5-next-js-apps-to-version-21-6.html)).
* If you have not customized the `\src\pages\api\sitemap.ts` file, replace it with the 22.0 version. Otherwise, do the following:
Add the following import statement:
```
import clientFactory from 'lib/graphql-client-factory';
```
Replace the endpoint and apiKey options for the GraphQLSitemapXmlService instantiation with the client factory:
```
const sitemapXmlService = new GraphQLSitemapXmlService({
clientFactory,
siteName: site.name,
});
```
* If you have not customized the `\src\pages\api\robots.ts` file, replace it with the 22.0 version. Otherwise, do the following:
Add the following import statement:
```
import clientFactory from 'lib/graphql-client-factory';
```
Remove the `config` import:
```
import config from 'temp/config';
```
Replace the endpoint and apiKey options for the GraphQLRobotsService instantiation with the client factory:
```
const sitemapXmlService = new GraphQLRobotsService({
clientFactory,
siteName: site.name,
});
```
### nextjs-multisite
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { GraphQLRobotsService } from '@sitecore-jss/sitecore-jss-nextjs';
import { siteResolver } from 'lib/site-resolver';
import config from 'temp/config';
import clientFactory from 'lib/graphql-client-factory';

const robotsApi = async (req: NextApiRequest, res: NextApiResponse): Promise<void> => {
res.setHeader('Content-Type', 'text/plain');
Expand All @@ -12,8 +12,7 @@ const robotsApi = async (req: NextApiRequest, res: NextApiResponse): Promise<voi

// create robots graphql service
const robotsService = new GraphQLRobotsService({
endpoint: config.graphQLEndpoint,
apiKey: config.sitecoreApiKey,
clientFactory,
siteName: site.name,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
import { AxiosDataFetcher, GraphQLSitemapXmlService, AxiosResponse } from '@sitecore-jss/sitecore-jss-nextjs';
import { siteResolver } from 'lib/site-resolver';
import config from 'temp/config';
import clientFactory from 'lib/graphql-client-factory';

const ABSOLUTE_URL_REGEXP = '^(?:[a-z]+:)?//';

Expand All @@ -19,8 +20,7 @@ const sitemapApi = async (

// create sitemap graphql service
const sitemapXmlService = new GraphQLSitemapXmlService({
endpoint: config.graphQLEndpoint,
apiKey: config.sitecoreApiKey,
clientFactory,
siteName: site.name,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
import express from 'express';
import compression from 'compression';
import 'dotenv/config';
import scProxy from '@sitecore-jss/sitecore-jss-proxy';
import { config } from './config';
//import { cacheMiddleware } from './cacheMiddleware';

const server = express();
const port = process.env.PORT || 3000;

// enable gzip compression for appropriate file types
server.use(compression());

// turn off x-powered-by http header
server.settings['x-powered-by'] = false;

// Serve static app assets from local /dist folder
server.use(
'/dist',
express.static('dist', {
fallthrough: false, // force 404 for unknown assets under /dist
})
);

/**
* Output caching, can be enabled,
* Read about restrictions here: {@link https://doc.sitecore.com/xp/en/developers/hd/22/sitecore-headless-development/caching-in-headless-server-side-rendering-mode.html}
*/
//server.use(cacheMiddleware());

server.use((req, _res, next) => {
// because this is a proxy, all headers are forwarded on to the Sitecore server
// but, if we SSR we only understand how to decompress gzip and deflate. Some
// modern browsers would send 'br' (brotli) as well, and if the Sitecore server
// supported that (maybe via CDN) it would fail SSR as we can't decode the Brotli
// response. So, we force the accept-encoding header to only include what we can understand.
if (req.headers['accept-encoding']) {
req.headers['accept-encoding'] = 'gzip, deflate';
}

next();
});

// For any other requests, we render app routes server-side and return them
server.use('*', scProxy(config.serverBundle.renderView, config, config.serverBundle.parseRouteUrl));

server.listen(port, () => {
console.log(`server listening on port ${port}!`);
});
import express from 'express';
import compression from 'compression';
import 'dotenv/config';
import scProxy from '@sitecore-jss/sitecore-jss-proxy';
import { config } from './config';
//import { cacheMiddleware } from './cacheMiddleware';

const server = express();
const port = process.env.PORT || 3000;

// enable gzip compression for appropriate file types
server.use(compression());

// turn off x-powered-by http header
server.settings['x-powered-by'] = false;

// Serve static app assets from local /dist folder
server.use(
'/dist',
express.static('dist', {
fallthrough: false, // force 404 for unknown assets under /dist
})
);

/**
* Output caching, can be enabled,
* Read about restrictions here: {@link https://doc.sitecore.com/xp/en/developers/hd/22/sitecore-headless-development/caching-in-headless-server-side-rendering-mode.html}
*/
//server.use(cacheMiddleware());

server.use((req, _res, next) => {
// because this is a proxy, all headers are forwarded on to the Sitecore server
// but, if we SSR we only understand how to decompress gzip and deflate. Some
// modern browsers would send 'br' (brotli) as well, and if the Sitecore server
// supported that (maybe via CDN) it would fail SSR as we can't decode the Brotli
// response. So, we force the accept-encoding header to only include what we can understand.
if (req.headers['accept-encoding']) {
req.headers['accept-encoding'] = 'gzip, deflate';
}

next();
});

// For any other requests, we render app routes server-side and return them
server.use('*', scProxy(config.serverBundle.renderView, config, config.serverBundle.parseRouteUrl));

server.listen(port, () => {
console.log(`server listening on port ${port}!`);
});

0 comments on commit d9175e0

Please sign in to comment.