#Remove Base Path from the url

8 messages · Page 1 of 1 (latest)

narrow bone
#

We have added basePath in our next config file, it's all working fine in local/development env, but we have a requirement to remove the basePath in the production url. Is this even possible?

floral hearthBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

rugged sand
#
const isProd = process.env.NODE_ENV === 'production'
 
module.exports = {
basePath: isProd ? '' : '/your_dev_path',
}
sage robin
#

Hi, you can do that by checking if the environment is in production or development. Take a look at the example below:

const apiUrl = process.env.NEXT_PUBLIC_PROD_API_URL // https://somewhere.com
const devApiUrl = process.env.NEXT_PUBLIC_DEV_API_URL // localhost:3000

export const API_URL = process.env.NODE_ENV === "production" ? apiUrl : devApiUrl
narrow bone
#

thanks for the response!

#

We are running turborepo with 3 apps in a single domain, all of the 3 nextjs app has base path so that the cloudfront can know which apps send a request, but in production we want to remove the base-path, is it still possible?

sage robin
narrow bone
#

is there a way to remove basePath on router.push("/path") ?