简体   繁体   English

我可以在github页面上托管我的React / redux(客户端和api服务器)项目吗?

[英]Can I host my React/redux (client and api server) project on github pages?

I know I can host my react/redux app on github pages by just serving the bundle.js and index.html, but can I also host an api server for the backend that is say username.github.io/api? 我知道我可以通过仅提供bundle.js和index.html将我的react / redux应用程序托管在github页面上,但是我还可以为后端托管一个名为username.github.io/api的api服务器吗?

The server uses node.js/express and they are separate directories. 服务器使用node.js / express,它们是单独的目录。

Also, can I make the server repository private and still host it on /api? 另外,我可以将服务器存储库设为私有,仍将其托管在/ api上吗?

I looked through the documentation on github pages about creating "projects" but it doesn't make much since to me. 我浏览了github页面上有关创建“项目”的文档,但是对我来说并没有多大帮助。

If anyone can shed some light on this, it would be must appreciated. 如果任何人都可以对此有所了解,那么我们将不胜感激。

No. GitHub Pages are static. 否。GitHub页面是静态的。 They're generated using a variation of Jekyll , a templated flat site generator. 它们是使用模板平台生成器Jekyll的变体生成的。 As such, they're only flat HTML, CSS and Javascript. 因此,它们只是纯HTML,CSS和Javascript。

You could host your frontend React application in them, but not server-side application code or a database. 您可以在其中托管前端React应用程序,但不能托管服务器端应用程序代码或数据库。

I suggest you run your front-end code on github while having an externally hosted api on say, AWS or google cloud. 我建议您在GitHub上运行前端代码,同时在AWS或Google Cloud上使用外部托管的api。

Amazon and google both provide free packages for small scale operations! 亚马逊和谷歌都为小规模运营提供免费软件包!

This way you can have your github page request data from AWS or google cloud! 这样,您可以让github页面从AWS或Google Cloud请求数据!

您不可以在Github页面上运行任何自定义服务器代码,而只能托管静态文件(HTML,图像,前端javascript等)。

You could do that if you are able to convert your code to static HTML + Resources (JS+CSS+IMAGES+FONTS..). 如果您能够将代码转换为静态HTML +资源(JS + CSS + IMAGES + FONTS ..),则可以这样做。 To do that, it is recommended to use webpack 为此,建议使用webpack

Once you finish coding, you build your project using : 完成编码后,您可以使用来构建项目:

NODE_ENV=production node_modules/webpack/bin/webpack.js --config webpack.config.prod.js

This will generate static HTML + JS of your code . 这将生成代码的静态HTML + JS。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在Heroku中托管我的API并从GitHub Pages访问它吗? - Can I host my API in Heroku, and access it from GitHub Pages? 如果它调用 API 来显示数据,我可以在 GitHub 页面上托管一个网站吗? - Can I host a website on GitHub Pages if it calls an API to display data? 如何在 Github Pages 上托管我的 javascript web 应用程序? - How can I host my javascript web application on Github Pages? 如何在我的 React 应用程序中隐藏 api 密钥并在 Github 中托管工作版本 - How could I hide api key in my React app and host the working version in Github 我无法使用 redux 和 react.js 从 github api 获得响应 - I can't get a response from github api using redux with react.js 如何在 Github 页面上发布我的 React 站点? - How do I publish my React site on Github Pages? 如何在正在运行的服务器中更新我的反应项目 - How I can update my react project in a running server 如何在没有组件闪烁的情况下根据来自我的 API 的数据重新路由 - React/Redux - How can I reroute based on data from my API without component flashing - React/Redux API 令牌添加到我的仓库中的 GitHub 机密,部署 GitHub 页面,我如何在 Z9E13B69D7F712DA9327102 中访问此机密? (简单的Node.js项目) - API token added to GitHub Secrets in my repo, deploying GitHub Pages, how do I access this Secret in Javascript? (Simple Node.js project) React 项目在 GitHub Pages 上显示空白页面 - React project displaying blank page on GitHub Pages
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM