节点JS应用程序部署到Heroku时中断

时间:2019-02-26 06:33:51

标签: node.js express heroku i18next

我希望你能帮助我。我自己没有找到可行的解决方案。我想将可在云9上运行的项目推送到heroku,但无法正常工作。下面是我的Herouku的日志文件。在Cloud 9上,一切都按扩展方式工作。

那是Heroku日志

    `Deploy 92065c2f by user kevinkamender@gmail.com
2019-02-26T05:51:36.407219+00:00 app[api]: Release v3 created by user kevinkamender@gmail.com
2019-02-26T05:51:37.000000+00:00 app[api]: Build succeeded
2019-02-26T05:51:50.500187+00:00 heroku[router]: at=info method=GET path="/" host=damp-oasis-72196.herokuapp.com request_id=4517cf2a-7dae-4e6e-8a0a-b7272f3bbf0b fwd="95.223.44.27" dyno=web.1 connect=0ms service=14ms status=500 bytes=404 protocol=https
2019-02-26T05:51:50.501865+00:00 app[web.1]: TypeError: res.local is not a function
2019-02-26T05:51:50.501881+00:00 app[web.1]: at module.exports (/app/i18n.js:19:7)
2019-02-26T05:51:50.501885+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2019-02-26T05:51:50.501887+00:00 app[web.1]: at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
2019-02-26T05:51:50.501889+00:00 app[web.1]: at /app/node_modules/express/lib/router/index.js:284:7
2019-02-26T05:51:50.501891+00:00 app[web.1]: at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
2019-02-26T05:51:50.501893+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/index.js:275:10)
2019-02-26T05:51:50.501895+00:00 app[web.1]: at expressInit (/app/node_modules/express/lib/middleware/init.js:40:5)
2019-02-26T05:51:50.501896+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2019-02-26T05:51:50.501898+00:00 app[web.1]: at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
2019-02-26T05:51:50.501900+00:00 app[web.1]: at /app/node_modules/express/lib/router/index.js:284:7
2019-02-26T05:51:50.819676+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=damp-oasis-72196.herokuapp.com request_id=f8c42cc6-0dfb-4931-bf57-21dc521836af fwd="95.223.44.27" dyno=web.1 connect=0ms service=2ms status=500 bytes=404 protocol=https
2019-02-26T05:51:50.819305+00:00 app[web.1]: TypeError: res.local is not a function
2019-02-26T05:51:50.819324+00:00 app[web.1]: at module.exports (/app/i18n.js:19:7)
2019-02-26T05:51:50.819326+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2019-02-26T05:51:50.819329+00:00 app[web.1]: at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
2019-02-26T05:51:50.819331+00:00 app[web.1]: at /app/node_modules/express/lib/router/index.js:284:7
2019-02-26T05:51:50.819333+00:00 app[web.1]: at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
2019-02-26T05:51:50.819335+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/index.js:275:10)
2019-02-26T05:51:50.819337+00:00 app[web.1]: at expressInit (/app/node_modules/express/lib/middleware/init.js:40:5)
2019-02-26T05:51:50.819338+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2019-02-26T05:51:50.819340+00:00 app[web.1]: at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
2019-02-26T05:51:50.819342+00:00 app[web.1]: at /app/node_modules/express/lib/router/index.js:284:7`

我的应用js

    var express     = require("express"),
i18next         = require("i18next"),
i18nextMiddleware = require("i18next-express-middleware"),
Backend         = require("i18next-node-fs-backend"),
bodyParser      = require("body-parser");

const app = express();
app.use(express.static("public"));
app.use(bodyParser.urlencoded({extended: true}));

i18next
  .use(Backend)
  .use(i18nextMiddleware.LanguageDetector)
  .init({
    backend: {
      loadPath: __dirname + '/locales/{{lng}}/{{ns}}.json',
      addPath: __dirname + '/locales/{{lng}}/{{ns}}.missing.json'
    },
    detection: {
      order: ['querystring', 'cookie'],
      caches: ['cookie']
    },
    fallbackLng: 'de',
    preload: ['de', 'en'],
    saveMissing: true
  });

app.set("view engine", "ejs");
app.use(i18nextMiddleware.handle(i18next));
// Routes

app.get("/", function(req, res){
    res.redirect("/home");
});


// Home

app.get("/home", function(req, res){
   res.render("index", {url: req.route.path});
});   


// Contact

app.get("/contact", function(req, res){
   res.render("contact", {url: req.route.path});
}); 

// Menu

app.get("/menu", function(req, res){
   res.render("menu", {url: req.route.path});
}); 


// Credits

app.get("/credits", function(req, res){
   res.render("credits", {url: req.route.path});
}); 

app.listen(process.env.PORT || 3000,  process.env.IP, function(){
    console.log("Coffe Site has started");
});

和我的包JSON

    {
  "name": "coffesite",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node app.js"
  },
  "author": "kevin kamender",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.18.3",
    "ejs": "^2.6.1",
    "express": "^4.16.4",
    "i18next": "^13.1.0",
    "i18next-express-middleware": "^1.7.1",
    "i18next-node-fs-backend": "^2.1.1"
  }
}

最好的问候

凯文

0 个答案:

没有答案