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

◇◆丶佛笑我妖孽 提交于 2021-02-11 12:38:21

问题


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?

The server uses node.js/express and they are separate directories.

Also, can I make the server repository private and still host it on /api?

I looked through the documentation on github pages about creating "projects" but it doesn't make much since to me.

If anyone can shed some light on this, it would be must appreciated.


回答1:


I suggest you run your front-end code on github while having an externally hosted api on say, AWS or google cloud.

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!




回答2:


No. GitHub Pages are static. They're generated using a variation of Jekyll, a templated flat site generator. As such, they're only flat HTML, CSS and Javascript.

You could host your frontend React application in them, but not server-side application code or a database.




回答3:


You are not allowed to run any custom server code on Github pages, you can only host static files (HTML, images, front-end javascript etc).




回答4:


You could do that if you are able to convert your code to static HTML + Resources (JS+CSS+IMAGES+FONTS..). To do that, it is recommended to use 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 .



来源:https://stackoverflow.com/questions/39359281/can-i-host-my-react-redux-client-and-api-server-project-on-github-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!