Is there wildcard for HTTP request routes on DigitalOcean App platform

1k Views Asked by At

I have a react app I have built and deployed to DigitalOcean App platform. I am wondering if there is a wild card I can use for http request routes. I am able to set paths for subdirectories but I can't figure out how to set up paths for a subdirectory with post ID.

For example:

mywebsite.com/subdirectory -> works and I can access this page

mywebsite.com/subdirectory/12345 -> This doesn't work when I add an ID after the subdirectory.

Is there a wildcard or something I can use for accessing specific pages with a subdirectory and ID.

Thank you

1

There are 1 best solutions below

0
On

To directly answer your question: No, it seems like wildcards are not supported by DO directly (at least not yet). It's not a common design to have wildcards directly in React app. Usually you have an index page and an in-browser router or a backend router of sorts.

If this is the case and you have a browser router, it means you don't actually have multiple pages, you just have an index.html, so you can just setup a Catchall to index.html. Any subpage will be redirected to that page, and then your browser router will render proper components and such. See DigitalOcean Web-Site for an explanation.

Second case is that you do need a complex routing, which will load a different HTML file where you need it. In this case it would be better to deploy in a container with something like an nginx front.

In this case you would have a Dockerfile that looks something like this:

FROM node:16.16.0 as dep_builder
COPY package.json ./
RUN npm i

FROM node:16.16.0 as builder
COPY . .
COPY --from=dep_builder node_modules ./node_modules
CMD npm run build

FROM nginx:alpine
EXPOSE 80
COPY --from=builder build /usr/share/nginx/html

And deploy it as a service with Dockerfile. See DO's site for exact instructions how to deploy a docker container. (Link to Digital Ocean Docs)