I have a site written in nextjs + cms stripi. There is a product catalog on the site, and when I add a new product, it appears in the list of products with all the necessary attributes, but when I follow the link to this product, I get a 404. In development mode, everything works fine, but I get an error on the server.
blank/[slug].js
export async function getStaticPaths() {
const blanksRes = await fetchAPI("/blanks", { fields: ["slug"] });
return {
paths: blanksRes.data.map((blank) => ({
params: {
slug: blank.attributes.slug,
},
})),
fallback: false,
};
}
export async function getStaticProps({ params }) {
const blanksRes = await fetchAPI("/blanks", {
filters: {
slug: params.slug,
},
populate: ["*", "slug"],
});
return {
props: {
blank: blanksRes.data[0],
},
revalidate: 1,
};
}
Card component:
const Card = ({ blank }) => {
<Link
key={blank.id}
href={`/blank/${blank.attributes.slug}`}
>
...
</Link>
next.config.js :
output: "standalone"
http://172.17.0.5:1337 - my forward strapi IP on the server
export function getStrapiURL(path = "") {
return `${
process.env.NEXT_PUBLIC_STRAPI_API_URL || "http://172.17.0.5:1337"
}${path}`;
}
Dockerfile:
FROM node:16-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
FROM node:16-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build --force
FROM node:16-alpine AS runner
WORKDIR /app
ENV NODE_ENV production
ENV NEXT_SHARP_PATH=/tmp/node_modules/sharp
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 80
ENV PORT 80
CMD ["node", "server.js"]
It seems that next js does not see the page after the build. If you make a build and upload to the server, then the page will be displayed. Strapi is located on the subdomain strapi.domainname.com , ssl certificate is installed. Tried to change localhost url to real localhost ip: localhost:1338 to 172.17.0.5:1337