首页 > 解决方案 > 当 heroku 节点应用程序尝试使用和尚访问 mlab db 插件时的状态 503

问题描述

我正在尝试在 heroku 上部署我的 express-mongodb 应用程序。我已经尝试在本地访问 heroky mlab 插件,并且本地服务器工作正常。但是当我在 heroku 上启动同一台服务器时,由于缺少数据库,服务器似乎无法解决请求。我想知道是僧侣js还是其他问题。




<!-- language: lang-javascript-->

const express = require('express');
    const bodyParser = require('body-parser');
    const monk = require('monk');
    const engines = require('consolidate');

    const app = express();

    const router = require('./routes/router');


    app.use(bodyParser.urlencoded({ extended: false }));

    app.use(express.static(`${__dirname}/public`));
    app.set('views', `${__dirname}/templates`);
    app.engine('html', engines.mustache);
    app.set('view engine', 'html');

    const db = monk('mongodb://<xxxx>.mlab.com:15338/heroku_1xx37v0b');
    db.then(() =>{
      console.log("connection success");
    }).catch((e)=>{
      console.error("Error !",e);
    });
    app.use((req, res, next) => { req.db = db; next(); });

    app.use('/', router);

    app.listen(process.env.PORT || 3000);


    // ask something to the db
    const collection = db.get('docUtenti');
    collection.findOne({type: "docTotUtenti" }).then((doc) => {console.log(doc);})


标签: mongodbexpressherokumlabmonk

解决方案


推荐阅读