如何将Strapi API和管理面板与另一个节点应用程序(使用Strapi API)集成? [英] How to integrate Strapi API and Admin Panel with another node app (that consumes Strapi API)?

查看:277
本文介绍了如何将Strapi API和管理面板与另一个节点应用程序(使用Strapi API)集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个使用Strapi Admin Panel api生成的应用程序,同时将其用作使用该api的网站.

I'm trying to develop an app that uses Strapi Admin Panel api generation, and, at the same time, serves as a website that consumes this api.

因此,基本上,我正在尝试建立一个网站:

So, basically, I'm trying to build a website:

  • 其中/api将服务器路由为Strapi API端点

  • where /api route servers as a Strapi API endpoint

其中/admin路由用作用于API创建的Strapi管理面板

where /admin route serves as a Strapi Admin Panel for API creation

配置了所有其他路由以服务我的网站的地方,即:

where all the other routes are configured to serve my website, i.e.:

  • /路线是我网站的着陆页

  • / route is the landing page of my website

/contacts是联系人页面

此外,网站的静态文件(html/css/etc)应该由分别使用生成的API(服务器端)的服务器提供.

And, moreover, the static files of the website (html/css/etc) should be served from the server that, respectively, consumes the generated API (server-side).

我希望我不要太含糊地表达自己.

I hope I'm not expressing myself too vaguely.

本质上,我需要将一个node.js应用程序(我的网站)与另一个node.js应用程序(Strapi)集成在一起,以使它们 作为一个无缝 .

Essentially, I need to integrate one node.js app (my website) with another node.js app (Strapi) in such a way that they work seamlessly together as one.

有人知道如何实现吗?

我在这里已经阅读了关于Stackoverflow和Strapi GitHub问题的一些答案,有人说,实现这一目标的方法是在不同的端口上运行两个单独的应用程序,但这对我来说不合适(或者也许对我来说不合适)我只是不了解一些基本知识.

I've read some answers here on Stackoverflow and on Strapi GitHub issues, and some people said that the way to achieve that is to run two separate apps on different ports, but it doesn't feel right to me (or maybe I just don't understand some basic stuff).

我需要制作一个应用程序,该应用程序基本上是一个简单的多页网站,但使用Strapi的api生成工具进行了增强.

What I need is to make a single app that is, basically, a simple multi-page website, but enhanced with api generation tools from Strapi.

我已经启动并运行了Strapi应用程序,我想也许应该在应用程序文件夹结构中找到一些位置放置我的网站(即,所有静态内容都放置在文件夹中),但是要将服务器放置在哪里?附带的东西?

I have my Strapi app up and running and I thought maybe I should find some place in the app folder structure to put my website (i.e. all the static stuff to the public folder), but where to put the server-side stuff?

我将需要使用模板引擎,因此再次出现将客户端文件放在哪里"的问题.我越深入研究代码,就会越困惑.

And I'll need to use a templating engine, so the question of "where to put the client-side files" arises again. The more I dig into the code, the more I get confused.

PS:我很好用Koa,它用作Strapi的服务器.

PS: I'm fine using Koa which is used as a server for Strapi.

PPS:此外,我计划在单个Dyno上将应用程序部署到Heroku(如果重要的话).

PPS: Further, I'm planning to deploy the app to Heroku on a single Dyno (if it is important).

推荐答案

好吧,我只是使用路由前缀,这是我建议的解决方案.

Okay I just played with the routing prefix and that is the solution I suggest you.

因此,您将必须构建自己的网站应用程序.并将构建版本推送到Strapi应用程序的./public文件夹中.

So you will have to build you website app. And push the build in the ./public folder of the Strapi application.

然后,在您的api/.../config/routes.json文件中,您将必须在每个路由的config键以及所有API中添加选项prefix

Then in your api/.../config/routes.json files you will have to add an option prefix in the config key of each of your routes and for all your APIs

{
  "routes": [
    {
      "method": "POST",
      "path": "/restaurants",
      "handler": "Restaurant.create",
      "config": {
        "policies": [],
        "prefix": "/api"
      }
    }
  ]
}

  • 因此,最后您将在/admin
  • 上拥有管理员
  • /api
  • 为前缀的API端点
  • 以及您在/
  • 上的网站/资产

    • So at the end you will have your admin on /admin
    • Your APIs endpoints prefixed by /api
    • And your website/assets on /
    • 这篇关于如何将Strapi API和管理面板与另一个节点应用程序(使用Strapi API)集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆