Я запускаю приложение .e js на heroku. Локально работает, но я получаю 500 ошибок при переходе по ссылке на Heroku. В основном я решил, что у него есть проблемы со всеми моими обработанными (req.render)
ссылками.
Вот мои app.js
ниже:
// app.js
const express = require('express');
const session = require('express-session');
const bodyParser = require('body-parser');
const cors = require('cors');
const flash = require('express-flash');
let path = require('path');
// Imports routes for the products
const photoalbum = require('./routes/photoalbum.route');
const events = require('./routes/events.route');
const verse = require('./routes/verse.route');
const trackRoute = require('./routes/tracks.route');
const fileRoute = require('./routes/files.route');
const slideRoute = require('./routes/slides.route');
const galleryCountCountRoute = require('./routes/gallery_count.route');
const userRoute = require('./routes/user.route');
/////////////////////
const app = express();
/////////////////////
// Set up mongoose connection
const mongoose = require('mongoose');
let dev_db_url = 'mongodb://Trex_son:S*******.mlab.com:43254/photoalbumdb';
let mongoDB = process.env.MONGODB_URI || dev_db_url;
mongoose.connect(mongoDB, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true });//mongoose.set('useFindAndModify', false);
mongoose.Promise = global.Promise;
let db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
module.exports = db;
module.exports = mongoose;
// app.use(bodyParser.json());
// app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json({limit: '10mb', extended: true}));
app.use(bodyParser.urlencoded({limit: '10mb', extended: true}));
app.use(cors());
app.use(session({secret: "S@****", resave: false, saveUninitialized:true, cookie: { maxAge: 60000 } }));
app.use(flash());
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'Views')));
app.use('/event-calendar-module', express.static(path.join(__dirname, 'event-calendar-module')));
app.use('/photoalbums', photoalbum);
app.use('/events', events);
app.use('/verse', verse);
app.use('/tracks', trackRoute);
app.use('/files', fileRoute);
app.use('/slides', slideRoute);
app.use('/gallerycount', galleryCountCountRoute);
app.use('/user', userRoute);
//handle 400
app.use((req, res)=> {
res.status(400);
res.sendFile(path.resolve('./Views', 'not-found.html'));
});
//handlle 500
app.use((error, req, res, next)=> {
res.status(500);
res.sendFile(path.resolve('./Views', 'error-not-found.html'));
});
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log('Server is up and running on port number ' + port);
});
Проблема возникает, когда я пытаюсь go к route user
, он содержит большинство моих отрендеренных файлов, т.е. https://localhost: 5000 / user / забыли . Здесь я получаю 5000 ошибок на Heroku, но работает локально.
вот мой user.route.js
код:
router.get('/forgot', user_controller.user_get_forgot);
Вот мой user.controller.js
код:
exports.user_get_forgot = function(req, res) {
res.render('forgot', {information: message});//, {User: req.user}
};
Пожалуйста, помогите решить эту проблему, если что-то еще нужно, дайте мне знать. Спасибо.
Это то, что журнал показал в тот момент:
2020-01-17T04:34:18.989581+00:00 heroku[router]: at=info method=GET path="/user/forgot" host=mfmsouth.herokuapp.com request_id=60316706-2a9a-44be-bf26-b1b6e476b7e7 fwd="67.167.63.7" dyno=web.1 connect=0ms service=4ms status=500 bytes=2436 protocol=http
2020-01-17T04:34:19.101234+00:00 heroku[router]: at=info method=GET path="/assets/login-logout/logout.js" host=mfmsouth.herokuapp.com request_id=4743ce6b-aef1-43ac-8590-109459382d57 fwd="67.167.63.7" dyno=web.1 connect=0ms service=3ms status=304 bytes=269 protocol=http
2020-01-17T04:34:19.055960+00:00 heroku[router]: at=info method=GET path="/assets/not-found/css/error-not-found.css" host=mfmsouth.herokuapp.com request_id=52edb65f-468f-438f-ae95-f7f5acb0d09b fwd="67.167.63.7" dyno=web.1 connect=0ms service=2ms status=304 bytes=269 protocol=http
2020-01-17T04:34:19.168099+00:00 heroku[router]: at=info method=GET path="/assets/not-found/js/error-not-found.js" host=mfmsouth.herokuapp.com request_id=19532d6b-3d76-4828-a4aa-2b1566492ae3 fwd="67.167.63.7" dyno=web.1 connect=0ms service=2ms status=304 bytes=268 protocol=http
После использования git status --ignored
я получаю этот журнал в CMD:
C:\Users\Tozyne\Desktop\mfm - git>git status --ignored
Refresh index: 100% (1925/1925), done.
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .idea/workspace.xml
modified: Views/assets/index-additional/js/index-basic.js
modified: Views/index.html
Untracked files:
(use "git add <file>..." to include in what will be committed)
Views/assets/images/slide/slides2020-01-12T19-52-54.296Z.jpg
Views/assets/images/slide/slides2020-01-12T19-53-31.511Z.jpg
Views/assets/index-additional/js/index-place-ratings.js
node_modules/async/CHANGELOG.md
node_modules/async/LICENSE
node_modules/async/README.md
node_modules/async/all.js
node_modules/async/allLimit.js
node_modules/async/allSeries.js
node_modules/async/any.js
node_modules/async/anyLimit.js
node_modules/async/anySeries.js
node_modules/async/apply.js
node_modules/async/applyEach.js
node_modules/async/applyEachSeries.js
node_modules/async/asyncify.js
node_modules/async/auto.js
node_modules/async/autoInject.js
node_modules/async/bower.json
node_modules/async/cargo.js
node_modules/async/cargoQueue.js
node_modules/async/compose.js
node_modules/async/concat.js
node_modules/async/concatLimit.js
node_modules/async/concatSeries.js
node_modules/async/constant.js
node_modules/async/detect.js
node_modules/async/detectLimit.js
node_modules/async/detectSeries.js
node_modules/async/dir.js
node_modules/async/dist/
node_modules/async/doDuring.js
node_modules/async/doUntil.js
node_modules/async/doWhilst.js
node_modules/async/each.js
node_modules/async/eachOf.js
node_modules/async/eachOfLimit.js
node_modules/async/eachOfSeries.js
node_modules/async/ensureAsync.js
node_modules/async/every.js
node_modules/async/everyLimit.js
node_modules/async/everySeries.js
node_modules/async/filter.js
node_modules/async/filterSeries.js
node_modules/async/find.js
node_modules/async/findLimit.js
node_modules/async/findSeries.js
node_modules/async/flatMap.js
node_modules/async/flatMapLimit.js
node_modules/async/flatMapSeries.js
node_modules/async/foldl.js
node_modules/async/foldr.js
node_modules/async/forEach.js
node_modules/async/forEachLimit.js
node_modules/async/forEachOfLimit.js
node_modules/async/forEachOfSeries.js
node_modules/async/forEachSeries.js
node_modules/async/groupBy.js
node_modules/async/groupByLimit.js
node_modules/async/groupBySeries.js
node_modules/async/index.js
node_modules/async/inject.js
node_modules/async/internal/DoublyLinkedList.js
node_modules/async/internal/Heap.js
node_modules/async/internal/asyncEachOfLimit.js
node_modules/async/internal/awaitify.js
node_modules/async/internal/breakLoop.js
node_modules/async/internal/consoleFunc.js
node_modules/async/internal/createTester.js
node_modules/async/internal/eachOfLimit.js
node_modules/async/internal/filter.js
node_modules/async/internal/getIterator.js
node_modules/async/internal/initialParams.js
node_modules/async/internal/isArrayLike.js
node_modules/async/internal/iterator.js
node_modules/async/internal/map.js
node_modules/async/internal/onlyOnce.js
node_modules/async/internal/parallel.js
node_modules/async/internal/promiseCallback.js
node_modules/async/internal/range.js
node_modules/async/internal/setImmediate.js
node_modules/async/internal/withoutIndex.js
node_modules/async/internal/wrapAsync.js
node_modules/async/log.js
node_modules/async/map.js
node_modules/async/mapLimit.js
node_modules/async/mapSeries.js
node_modules/async/mapValuesSeries.js
node_modules/async/memoize.js
node_modules/async/nextTick.js
node_modules/async/package.json
node_modules/async/parallel.js
node_modules/async/parallelLimit.js
node_modules/async/priorityQueue.js
node_modules/async/queue.js
node_modules/async/race.js
node_modules/async/reduce.js
node_modules/async/reduceRight.js
node_modules/async/reflect.js
node_modules/async/reject.js
node_modules/async/rejectLimit.js
node_modules/async/rejectSeries.js
node_modules/async/retryable.js
node_modules/async/selectLimit.js
node_modules/async/seq.js
node_modules/async/setImmediate.js
node_modules/async/some.js
node_modules/async/someLimit.js
node_modules/async/someSeries.js
node_modules/async/sortBy.js
node_modules/async/times.js
node_modules/async/timesSeries.js
node_modules/async/transform.js
node_modules/async/tryEach.js
node_modules/async/unmemoize.js
node_modules/async/until.js
node_modules/async/waterfall.js
node_modules/async/wrapSync.js
node_modules/connect-flash/
node_modules/ejs/
node_modules/express-flash/
node_modules/nodemailer/
I видите, это не добавляет node_modules/ejs/
.