在Netlify或Heroku部署一个完整的MERN网络应用程序。

编程入门 行业动态 更新时间:2024-10-07 00:18:29

在Netlify或Heroku部署一个完整的MERN网络<a href=https://www.elefans.com/category/jswz/34/1771452.html style=应用程序。"/>

在Netlify或Heroku部署一个完整的MERN网络应用程序。

我想部署一个完整的堆栈MERN网络AP到Netlify oor Heroku,但它总是给我一个错误,我试了几件事情,但没有人可以帮助我吗?这个代码部署在Heroku和给我一个错误的页面不可用,我试了几次,没有成功的

Github代码。https:/githubhazem-kamelGuestbook-MERN。

当尝试使用GitHub和Heroku部署时的日志。

日志 :

-----> Node.js app detected

-----> Creating runtime environment

       NPM_CONFIG_LOGLEVEL=error
       NODE_ENV=production
       NODE_MODULES_CACHE=true
       NODE_VERBOSE=false

-----> Installing binaries
       engines.node (package.json):  13.8.0
       engines.npm (package.json):   unspecified (use default)

       Resolving node version 13.8.0...
       Downloading and installing node 13.8.0...
       Using default npm version: 6.13.6

-----> Installing dependencies
       Prebuild detected (node_modules already exists)
       Rebuilding any native modules

       > [email protected] install /tmp/build_b3af99df845ca37998271723b79f6f44/node_modules/bcrypt
       > node-pre-gyp install --fallback-to-build

       [bcrypt] Success: "/tmp/build_b3af99df845ca37998271723b79f6f44/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node" already installed
       Pass --update-binary to reinstall or --build-from-source to recompile

       Installing any new modules (package.json)
       audited 286 packages in 2.176s

       3 packages are looking for funding
         run `npm fund` for details

       found 0 vulnerabilities


-----> Build
       Running heroku-postbuild

       > [email protected] heroku-postbuild /tmp/build_b3af99df845ca37998271723b79f6f44
       > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client

       audited 1926 packages in 13.657s

       58 packages are looking for funding
         run `npm fund` for details

       found 2 vulnerabilities (1 low, 1 high)
         run `npm audit fix` to fix them, or `npm audit` for details

       > [email protected] build /tmp/build_b3af99df845ca37998271723b79f6f44/client
       > react-scripts build

       Creating an optimized production build...
       Compiled with warnings.

       ./src/components/Login/Login.js
         Line 12:6:  React Hook useEffect has a missing dependency: 'Redirect'. Either include it or remove the dependency array  react-hooks/exhaustive-deps

       ./src/components/Register/Register.js
         Line 12:6:  React Hook useEffect has a missing dependency: 'Redirect'. Either include it or remove the dependency array  react-hooks/exhaustive-deps

       ./src/components/Chats/Chats.js
         Line 36:6:  React Hook useEffect has missing dependencies: 'friend' and 'user'. Either include them or remove the dependency array  react-hooks/exhaustive-deps

       ./src/components/Dashboard/Dashboard.js
         Line 46:11:  Nested block is redundant  no-lone-blocks

       Search for the keywords to learn more about each warning.
       To ignore, add // eslint-disable-next-line to the line before.

       The project was built assuming it is hosted at /.
       You can control this with the homepage field in your package.json.

       The build folder is ready to be deployed.
       You may serve it with a static server:

         npm install -g serve
         serve -s build

       Find out more about deployment here:

         bit.ly/CRA-deploy
-----> Caching build
       - node_modules

-----> Pruning devDependencies
       audited 286 packages in 2.127s

       3 packages are looking for funding
         run `npm fund` for details

       found 0 vulnerabilities


-----> Build succeeded!
-----> Discovering process types
       Procfile declares types     -> (none)
       Default types for buildpack -> web
-----> Compressing...
       Done: 84.9M
-----> Launching...
       Released v3
       / deployed to Heroku```
回答如下:

在你的node后台package.json中写下这些脚本。

    "scripts": {
    "start": "node server.js",
    "server": "nodemon server.js",
    "client": "npm start --prefix client",
    "clientinstall": "npm install --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\"",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},

在你的server.js的底部写上这句话。

// Serve static assets in production
if (process.env.NODE_ENV == 'production') {
    // Set static folder
    app.use(express.static('client/build'));

    app.get('*', (req, res) =>
        res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
    );
}
const PORT = process.env.PORT || 8000;
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));

然后你就完成了。只需通过Heroku登录并设置git分支。然后做

git push heroku master

更多推荐

在Netlify或Heroku部署一个完整的MERN网络应用程序。

本文发布于:2024-05-13 12:06:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1759511.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   完整   网络   Netlify   Heroku

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!