Skip to content

Commit 7252426

Browse files
committed
Merge branch 'pull/1289'
2 parents ab21caf + a64f3da commit 7252426

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

.envrc.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
44
export NEXT_PUBLIC_ANALYTICS_DOMAIN=string.test
55
export NEXT_PUBLIC_ANALYTICS_ENABLED=false
66
export NODENV_VERSION=20.6.1
7+
export NEXT_PUBLIC_BASE_PATH=/string # supply this if you are deploying to a sub-path of your domain like https://tools.example.com/string

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ WORKDIR /app
1313
COPY --from=deps /app/node_modules ./node_modules
1414
COPY . .
1515

16+
# Set environment variables
17+
ARG NEXT_PUBLIC_BASE_PATH=""
18+
ENV NEXT_PUBLIC_BASE_PATH=$NEXT_PUBLIC_BASE_PATH
19+
1620
ENV NEXT_TELEMETRY_DISABLED 1
1721
ENV OUTPUT_STANDALONE 1
1822
RUN yarn build

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,25 @@ The quickest way to deploy string.is is to use the [Vercel Platform](https://ver
131131
132132
Unfortunately string.is doesn't currently support static builds via `next export` (which would allow hosting on eg. S3), because the `i18n` feature it uses is not currently supported for static builds.
133133

134+
### Deploy string.is under a sub-path of a domain
135+
136+
Set the `NEXT_PUBLIC_BASE_PATH` environment variable to the sub-path, then build the project before deploying. This value must be set at build time and cannot be changed without re-building as the value is inlined in the client-side bundles.
137+
138+
For example, if you're deploying to `https://tools.example.com/string-is`, you'll need to set `NEXT_PUBLIC_BASE_PATH` to `/string-is`. You don't need to set this variable if you're deploying to the root of a domain.
139+
140+
Build and run with Docker:
141+
142+
```bash
143+
docker build -t string-is --build-arg NEXT_PUBLIC_BASE_PATH="/string-is" .
144+
docker run -p 3000:3000 string-is
145+
```
146+
147+
Or build and run with `docker-compose`:
148+
149+
```bash
150+
export NEXT_PUBLIC_BASE_PATH="/string-is"
151+
docker-compose up --build
152+
```
134153

135154
## Localization
136155

docker-compose.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ version: '3.3'
33

44
services:
55
string-is:
6-
build: .
6+
build:
7+
context: .
8+
args:
9+
NEXT_PUBLIC_BASE_PATH: ${NEXT_PUBLIC_BASE_PATH:-}
710
ports:
811
- '3000:3000'
912
image: string-is

next.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,8 @@ module.exports = nextTranslate({
109109

110110
return config
111111
},
112+
// To deploy a Next.js application under a sub-path of a domain you can use the basePath config option.
113+
// See https://nextjs.org/docs/app/api-reference/next-config-js/basePath
114+
// Note: basePath must be set at build time and cannot be changed without re-building as the value is inlined in the client-side bundles.
115+
basePath: process.env.NEXT_PUBLIC_BASE_PATH || '',
112116
})

0 commit comments

Comments
 (0)