【发布时间】:2021-04-18 22:04:30
【问题描述】:
我无法解决某个 Heroku 问题(图像存储/检索),所以我正在尝试使用 Namecheap。
我从 Namecheap 购买了一个域和 Web 主机服务器,因此我可以部署我为客户制作的完整的 MERN 堆栈应用程序。
应用文件结构:
AppName
|
--client <<~~create-react-app
|
--middleware
|
--models
|
--node_modules
|
--routes
|
--uploads
|
--.env
|
--.gitignore
|
--package-lock.json
|
--package.json
|
--README.md
|
--server.js
-
将我的域的名称服务器设置为
Namecheap Web hosting DNS(namecheap 指南说明) -
在
/client中运行npm run build(虽然没有做serve -s build)生成/client/build
server.js
// For Deployment
if(process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, 'client', 'build')));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'client', 'build', 'index.html'));
});
};
-
通过
Git Version ControlcPanel 选项将我的 git repo 连接到域 -
已将我所有的应用文件上传到 cPanel
File Manager(由Git Version Control自动完成) -
使用 cPanel 的
Setup NodeJS App功能
设置 NodeJS 应用程序需要多个表单字段:
NodeJS version: 12.19.1 <<~~slightly higher than mine, their support team advised me to do that
Application mode: Production
Application root: repositories/AppName <<~~path from the cPanel File Manager
Application URL: my-domain.com
Application Startup File: repositories/ChrisPortfolio/client/build/index.html <<~~this has been a guessing game, more notes below
至于Application Startup File,我尝试了server.js,并在这里尝试了一些东西。
我尝试的一切都导致在浏览器中访问应用程序并点击“未找到”页面。
但是,使用repositories/ChrisPortfolio/client/build/index.html,应用程序会说“它有效!”并显示我选择的节点版本,但是.. 它没有显示实际的应用程序。
有一个选项可以从 cPanel NodeJS 仪表板内部运行 npm install,我确保这样做了。
我想也许我还需要让它在 /client 目录中运行 npm install,但是仪表板不允许您从希望运行命令的位置中进行选择。
无论如何,这就是我所在的位置。希望这对某人来说很熟悉。
【问题讨论】:
标签: node.js cpanel shared-hosting mern namecheap