I recently updated my personal website (using Gitlab Pages from Gitlab.com) using a NextJS SSG project, that you can see here.
As I’m close to complete the job (everything works fine), I checked my SEO on GT Metrix and Twitter Card Validator… with an unpleasant surprise (!): for some pages (but not every page), GT Metrix tells me he get 503 error, and for the same pages Twitter validator shows me a link to Gitlab signin page (apparently redirected).
Here are the pages with errors:
- https://soykje.gitlab.io/fr and https://soykje.gitlab.io/en
- https://soykje.gitlab.io/fr/blog and https://soykje.gitlab.io/en/blog (blog posts are ok)
I insist that the site works fine when browsing, and as I was checking for possible NextJS coding issues, I was not able to find anything (routing and configuration seem to have been done correctly).
For the record, I'm using NextJS 9.5, and I use also a locale context to provide multilingual support... Maybe it is related? I checked my code and it seems ok, but the problem must be somewhere, in my code or in my repo settings?
I tried to clear runners cache, delete my page before rebuilding, … But nothing works. Here is some configuration files, if that helps:
gitlab-ci.yml
image: node
cache:
paths:
- node_modules/
pages:
before_script:
# Clean public folder
- find public -mindepth 1 -maxdepth 1 -type d | xargs rm -rf
- find public -type f -name "*.html" | xargs rm -rf
# Install packages
- npm install
script:
# Build application and move content to public folder
- npm run publish
- mv out/* public
after_script:
# Cleanup
- rm -rf out
artifacts:
paths:
- public
only:
- master
next.config.js
const isProd = process.env.NODE_ENV === 'production'
module.exports = {
assetPrefix: isProd ? '/' : ''
}
I'm totally lost here, and these problems, even if not blocking browsing, are still issues... so any help would be really great!
Thank you all in advance!
After a few investigation it appeared that the
trailingSlash: true
option (onnext.config.js
) solves the problem... Not sure to understand why :/[Update] After searching in Gitlab Pages documentation, and inspecting my output files with or without this
trailingSlash
option, it seems that the origin of this problem has to be shared between Gitlab Pages' url resolution and Next.js export methods... It appears that when using Gitlab Pages we need to use this option to make everything work correctly.