Skip to content

Commit

Permalink
fix: "localhost" is not used into Clever Cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
sneko committed Feb 21, 2024
1 parent d64f37a commit aa06c3b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ ARG NODE_VERSION=18.19.0
ARG RUBY_VERSION=3.2.2-r1
ARG PIP_VERSION=23.3.1-r0
ARG PRISMA_VERSION=4.16.2
ARG APP_HOST=localhost
ARG PORT=3000

FROM node:${NODE_VERSION}-alpine

ARG RUBY_VERSION
ARG PIP_VERSION
ARG PRISMA_VERSION
ARG APP_HOST
ARG PORT

RUN apk add --no-cache \
Expand Down Expand Up @@ -63,6 +65,7 @@ COPY --chown=nextjs:nodejs "public" "./public"

ENV PRISMA_VERSION $PRISMA_VERSION

ENV APP_HOST $APP_HOST
ENV PORT $PORT
EXPOSE $PORT

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ For each build and runtime (since they are shared), you should have set some env

- `CC_DOCKERFILE`: [TO_DEFINE] _(should be `Dockerfile.prod.clevercloud` for the production environment and `Dockerfile.dev.clevercloud` for the development one. It's used during the build stage on the Clever Cloud side)_
- `CC_DOCKER_EXPOSED_HTTP_PORT`: `3000` _(it tells to Clever Cloud the port we are listening on)_
- `APP_HOST`: [GENERATED] _(as of today our commands when starting cannot rely on using `localhost` since Clever Cloud is not providing the local/network IP so you have to look at logs the first time to then adjust this variable. Note only the network one seems constant over time, the localhost one changes at each restart. If it breaks, we could use the domain name)_
- `PORT`: `3000` _(since Clever Cloud has a default value for this variable we have to override it)_
- `APP_MODE`: `prod` _(can be `dev` in case you would like to deploy a development environment)_
- `DATABASE_URL`: `$POSTGRESQL_ADDON_URI` _(you must copy/paste the value provided by Clever Cloud into `$POSTGRESQL_ADDON_URI`, and note you must add as query parameter `sslmode=prefer`)_
- `MAINTENANCE_API_KEY`: [SECRET] _(random string that can be generated with `openssl rand -base64 32`. Note this is needed to perform maintenance through dedicated API endpoints)_
Expand Down
2 changes: 1 addition & 1 deletion src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function getBaseUrl() {
return '';
}

return `http://localhost:${process.env.PORT ?? getListeningPort()}`;
return `http://${process.env.NEXT_PUBLIC_APP_HOST ?? 'localhost'}:${process.env.PORT ?? getListeningPort()}`;
}

export function getListeningPort() {
Expand Down
4 changes: 2 additions & 2 deletions start-and-wait-to-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ check_server_and_init() {
counter=0

while true; do
response=$(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$PORT)
response=$(curl --write-out %{http_code} --silent --output /dev/null http://$APP_HOST:$PORT)
if [ "$response" = "200" ]; then
break
fi
Expand All @@ -44,7 +44,7 @@ check_server_and_init() {
counter=$((counter+1))
done

curl http://localhost:$PORT/api/init
curl http://$APP_HOST:$PORT/api/init
}

# In parallel wait for the server readiness to init some services
Expand Down

0 comments on commit aa06c3b

Please sign in to comment.