Skip to content

Commit

Permalink
Merge branch 'pull/1289'
Browse files Browse the repository at this point in the history
  • Loading branch information
recurser committed Jan 3, 2024
2 parents ab21caf + a64f3da commit 7252426
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions .envrc.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export NEXT_PUBLIC_ANALYTICS_DOMAIN=string.test
export NEXT_PUBLIC_ANALYTICS_ENABLED=false
export NODENV_VERSION=20.6.1
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
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Set environment variables
ARG NEXT_PUBLIC_BASE_PATH=""
ENV NEXT_PUBLIC_BASE_PATH=$NEXT_PUBLIC_BASE_PATH

ENV NEXT_TELEMETRY_DISABLED 1
ENV OUTPUT_STANDALONE 1
RUN yarn build
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,25 @@ The quickest way to deploy string.is is to use the [Vercel Platform](https://ver
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.

### Deploy string.is under a sub-path of a domain

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.

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.

Build and run with Docker:

```bash
docker build -t string-is --build-arg NEXT_PUBLIC_BASE_PATH="/string-is" .
docker run -p 3000:3000 string-is
```

Or build and run with `docker-compose`:

```bash
export NEXT_PUBLIC_BASE_PATH="/string-is"
docker-compose up --build
```

## Localization

Expand Down
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ version: '3.3'

services:
string-is:
build: .
build:
context: .
args:
NEXT_PUBLIC_BASE_PATH: ${NEXT_PUBLIC_BASE_PATH:-}
ports:
- '3000:3000'
image: string-is
4 changes: 4 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,8 @@ module.exports = nextTranslate({

return config
},
// To deploy a Next.js application under a sub-path of a domain you can use the basePath config option.
// See https://nextjs.org/docs/app/api-reference/next-config-js/basePath
// 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.
basePath: process.env.NEXT_PUBLIC_BASE_PATH || '',
})

1 comment on commit 7252426

@vercel
Copy link

@vercel vercel bot commented on 7252426 Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

string-is – ./

string-is-recurser.vercel.app
string-is-git-main-recurser.vercel.app
string.is
www.string.is

Please sign in to comment.