Я боролся с этим разделом около 10+ часов. Я попытался сделать свое исследование и обнаружить проблему. Я попробовал несколько решений, но не могу заставить его работать на меня. У меня все настроено точно так, как BradTraversy, но по какой-то причине мое не развертывается. Локальное развитие прекрасно работает как с передней, так и с задней частью.
Проблема в том, что при развертывании в производство на Heroku. Он показывает внешний интерфейс, но затем внутренний сервер решает не работать. Я опубликую репозиторий в репо после этой строки.
Спасибо вам, ребята, за то, что вы нашли время помочь мне.
Репозиторий: https://github.com/bradtraversy/devconnector_2.0
Я развертываю приложение в Heroku, вводя:
git push heroku master
Затем проверяю журналы, введя:
heroku logs --tail
Ошибки, которые я получаю в этом журнале:
heroku [router]: at = error code = H13 desc = "Соединение закрыто без ответа" метод = POST path = "/ api / users service = 10164ms status = 503"
и
heroku [router ]: at = код ошибки = H10 desc = метод "Приложение зависло" = путь POST = "/ api / users" service = status = 503
2020-02-05T02:14:30.248090+00:00 heroku[web.1]: State changed from up to crashed
2020-02-05T02:14:30.225433+00:00 heroku[web.1]: Process exited with status 1
2020-02-05T02:24:44.491342+00:00 heroku[web.1]: State changed from crashed to starting
2020-02-05T02:24:52.827814+00:00 heroku[web.1]: Starting process with command `npm start`
2020-02-05T02:24:55.035533+00:00 app[web.1]:
2020-02-05T02:24:55.035564+00:00 app[web.1]: > devconnector@1.0.0 start /app
2020-02-05T02:24:55.035566+00:00 app[web.1]: > node server.js
2020-02-05T02:24:55.035568+00:00 app[web.1]:
2020-02-05T02:24:55.719810+00:00 app[web.1]: Server started on port 58394
2020-02-05T02:24:56.130106+00:00 heroku[web.1]: State changed from starting to up
2020-02-05T02:25:25.780242+00:00 app[web.1]: Server selection timed out after 30000 ms
2020-02-05T02:25:25.798194+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-02-05T02:25:25.798598+00:00 app[web.1]: npm ERR! errno 1
2020-02-05T02:25:25.799936+00:00 app[web.1]: npm ERR! devconnector@1.0.0 start: `node server.js`
2020-02-05T02:25:25.800096+00:00 app[web.1]: npm ERR! Exit status 1
2020-02-05T02:25:25.800260+00:00 app[web.1]: npm ERR!
2020-02-05T02:25:25.800376+00:00 app[web.1]: npm ERR! Failed at the devconnector@1.0.0 start script.
2020-02-05T02:25:25.800502+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-02-05T02:25:25.809573+00:00 app[web.1]:
2020-02-05T02:25:25.809899+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-02-05T02:25:25.810391+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-02-05T02_25_25_801Z-debug.log
2020-02-05T02:25:25.929540+00:00 heroku[web.1]: State changed from up to crashed
2020-02-05T02:25:25.910090+00:00 heroku[web.1]: Process exited with status 1
2020-02-05T02:26:34.034101+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/api/users" host=floating-eyrie-69630.herokuapp.com request_id=c4fd2b74-4a3b-4857-b954-81ee18c94b8a fwd="71.178.243.54" dyno= connect= service= status=503 bytes= protocol=https
2020-02-05T02:30:24.143711+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/api/users" host=floating-eyrie-69630.herokuapp.com request_id=306e3957-63bc-4927-a8d7-d92cfd73790d fwd="71.178.243.54" dyno=web.1 connect=0ms service=8196ms status=503 bytes=0 protocol=https
2020-02-05T02:30:24.137543+00:00 app[web.1]: Server selection timed out after 30000 ms
2020-02-05T02:30:24.146314+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-02-05T02:30:24.146527+00:00 app[web.1]: npm ERR! errno 1
2020-02-05T02:30:24.147415+00:00 app[web.1]: npm ERR! devconnector@1.0.0 start: `node server.js`
2020-02-05T02:30:24.147505+00:00 app[web.1]: npm ERR! Exit status 1
2020-02-05T02:30:24.147637+00:00 app[web.1]: npm ERR!
2020-02-05T02:30:24.147718+00:00 app[web.1]: npm ERR! Failed at the devconnector@1.0.0 start script.
2020-02-05T02:30:24.147802+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-02-05T02:30:24.153368+00:00 app[web.1]:
2020-02-05T02:30:24.153531+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-02-05T02:30:24.153633+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-02-05T02_30_24_148Z-debug.log
2020-02-05T02:30:24.230309+00:00 heroku[web.1]: State changed from up to crashed
2020-02-05T02:30:24.141581+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/api/users" host=floating-eyrie-69630.herokuapp.com request_id=810181a6-17d8-4718-a417-18e54decccdd fwd="71.178.243.54" dyno=web.1 connect=0ms service=10164ms status=503 bytes=0 protocol=https
2020-02-05T02:30:24.143736+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/api/users" host=floating-eyrie-69630.herokuapp.com request_id=ea00ea5c-3403-4db9-8df6-d895c612dc3b fwd="71.178.243.54" dyno=web.1 connect=0ms service=8826ms status=503 bytes=0 protocol=https
2020-02-05T02:30:24.142003+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/api/users" host=floating-eyrie-69630.herokuapp.com request_id=62b8da0b-d894-4d38-9c2d-496833c0ec14 fwd="71.178.243.54" dyno=web.1 connect=0ms service=9308ms status=503 bytes=0 protocol=https
2020-02-05T02:30:24.212393+00:00 heroku[web.1]: Process exited with status 1
Несколько замечаний, я все правильно настроено. У меня установлен mongoURI с правильно введенными именем пользователя и паролем
config / production. json
{
"mongoURI": "mongodb+srv://myusername:mypassword@cluster0-ziuao.mongodb.net/test?retryWrites=true&w=majority",
"jwtSecret": "secret",
"githubClientId": "",
"githubSecret": ""
}
config / db
const mongoose = require('mongoose');
const config = require('config');
const db = config.get('mongoURI');
const connectDB = async () => {
try {
await mongoose.connect(db, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true
});
console.log('MongoDB Connected...');
} catch (err) {
console.error(err.message);
// Exit process with failure
process.exit(1);
}
};
module.exports = connectDB;
сервер. js
const express = require('express');
const connectDB = require('./config/db');
const path = require('path');
const app = express();
// Connect Database
connectDB();
// Init Middleware
app.use(express.json({ extended: false }));
// Define Routes
app.use('/api/users', require('./routes/api/users'));
app.use('/api/auth', require('./routes/api/auth'));
app.use('/api/profile', require('./routes/api/profile'));
app.use('/api/posts', require('./routes/api/posts'));
// 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 || 5000;
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));
Мне интересно, что может быть причиной этого? Будем весьма благодарны за любые полезные ответы и / или pu sh в правильном направлении! Спасибо!