是否有Digitalocean App Platform上HTTP请求路线的通配符

发布于 2025-01-30 23:54:21 字数 282 浏览 4 评论 0原文

我有一个我已经构建并部署到Digitalocean应用程序平台的React应用程序。我想知道是否有通配符可以用于HTTP请求路线。我能够为子目录设置路径,但我无法弄清楚如何设置具有Post ID的子目录的路径。

例如:

mywebsite.com/subdirectory->作品,我可以访问此页面

mywebsite.com/subdirectory/12345->当我在子目录之后添加ID时,这无效。

是否有通配符或可以使用子目录和ID访问特定页面的东西。

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴骨ら 2025-02-06 23:54:21

直接回答您的问题:不,似乎不直接支持通配符(至少还没有)。直接在React App中使用通配符并不是常见的设计。通常,您有一个索引页面和一个浏览器路由器或各种后端路由器。

如果是这种情况,并且有一个浏览器路由器,则意味着您实际上没有多个页面,只需index.html,因此您只需将Catchall设置为index.html。任何子页面都将被重定向到该页面,然后您的浏览器路由器将呈现适当的组件等。 See DigitalOcean Web - 点用于解释。

第二种情况是您确实需要一个复杂的路由,该路由将在需要的地方加载其他HTML文件。在这种情况下,最好将部署在具有NGINX前线之类的容器中。

在这种情况下,您将拥有一个看起来像这样的Dockerfile:

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

并将其部署为使用Dockerfile的服务。有关如何部署Docker容器的确切说明,请参见DO的网站。 (链接到数字海洋文档

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文