简体   繁体   English

Redux-如何将Express Server部署到Heroku

[英]Redux - How to deploy Express Server to Heroku

I have created an app for login and log out users. 我已经创建了一个用于登录和注销用户的应用程序。 Im using express and Redux 我正在使用Express和Redux

I have 2 folders, one for the client and another for the server side. 我有2个文件夹,一个用于客户端,另一个用于服务器端。 It works on localhost, but now i want to make it online using heroku. 它可以在localhost上运行,但是现在我想使用heroku使其联机。 I know how to deploy simple app´s in Heroku, but not apps whit server, im not understanding the logic. 我知道如何在Heroku中部署简单的应用程序,但不知道如何在服务器上部署应用程序,因为我不了解其逻辑。 I have created a database using mongolab, but thats it, i dont know what to do more. 我已经使用mongolab创建了一个数据库,但是就这样,我不知道该怎么做。

Please Help. 请帮忙。

This is my index.js on my server. 这是我服务器上的index.js。

const express = require('express');
const http = require('http');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const app = express();
const router = require('./router');
const mongoose = require('mongoose');
const cors = require('cors');

// DB Setup
//mongoose.connect('mongodb://localhost:hugo/hugo');
mongoose.connect('mongodb://*****:********@ds143608.mlab.com:43608/portfolio');

// App Setup
app.use(morgan('combined'));
app.use(cors());
app.use(bodyParser.json({type: '*/*'}));
router(app);

// Server Setup

const port = process.env.PORT || 3090;
const server = http.createServer(app);
server.listen(port);
console.log('Server Listening On:', port);

The best solution would be to combine the client and server into ONE app and deploy that to Heroku: 最好的解决方案是将客户端和服务器合并为一个应用程序,然后将其部署到Heroku:

https://daveceddia.com/create-react-app-express-backend/ https://daveceddia.com/create-react-app-express-backend/

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM