DEV Community

Toufic Nabi
Toufic Nabi

Posted on

23

Deploying Next.JS app in Godaddy shared hosting correctly.

Hosting a react app (next.js) in Godaddy Shared hosting can be a confusing job. Specially if you are using server side rendering. Godaddy shared hosting (in most cases) does not allow node apps.

But we can take advantage of the Static generation feature. Using Static generation we can generate a static html site. You can follow the following steps:

  • Go to package.json
  • Under Scripts object add a new key value pair like this
    "genetate": "next build && next export"

  • then, navigate to next.config.js

  • Add the following code:

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  output: 'export',
  distDir: 'dist',
  trailingSlash: true,
  assetPrefix: '.',
}

module.exports = nextConfig;
Enter fullscreen mode Exit fullscreen mode

then from your terminal run the command:
npm run generate

Important thing to note here is the trailingSlash: true,
In godaddy if you navigate the site using the say navigation bar it works but if you reload a page other than the home page
for example /about/
it looks for the about directory which does not exist. So with trailingSlash: true, this command your pages will go on their respective directory.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (2)

Collapse
 
fsolarv profile image
FelipeS

Hello! This only work with static pages or can be dynamic?

Collapse
 
ndungutsecharles103 profile image
Ndungutse Charles

It can't be dynamic

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay