I have a vuejs app which set up with vue cli, and i'm trying deploy my app to heroku.
Here's my server :
const express = require('express');
const port = process.env.PORT || 8080;
const app = express();
app.use(express.static(__dirname + "/dist/"));
app.get(/.*/ , function(req,res) {
res.sendfile(__dirname + "/dist/index.html");
});
app.listen(port);
console.log("Server started...");
I remove dist from gitignore,
I aded a start point like "start": "node server.js" in package.json
Here's what i see on console :
Failed to load resource: the server responded with a status of 503 (Service Unavailable) /favicon.ico:1
Here's heroku logs :
2019-12-13T08:55:49.464914+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=followgoals.herokuapp.com request_id=09df33ae-96ab-415a-929b-530fb943318d fwd="37.130.123.179" dyno= connect= service= status=503 bytes= protocol=https
2019-12-13T08:55:49.828341+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=followgoals.herokuapp.com request_id=21de7307-502e-4104-a648-8e6b0832a3fe fwd="37.130.123.179" dyno= connect= service= status=503 bytes= protocol=https
So what can i do the fix problem ?
I had the same problem, worked on local, 503 error on heroku, and I fixed it by going to my db cloud service(mongodb atlas), and changed the white list setting on my cluster from "home" to "anywhere".
https://www.youtube.com/watch?v=leNNivaQbDY&t=31s
Related
I'm trying to deploy my backend express server with mongodb to heroku. it is successful but when I view the webapp I get Application error and the logs in the logs it says this. I have googled around a lot but I cannot seem to find a solution for it
2022-05-27T06:07:55.783858+00:00 app[web.1]: > backend#1.0.0 start
2022-05-27T06:07:55.783858+00:00 app[web.1]: > nodemon server.js
2022-05-27T06:07:55.783859+00:00 app[web.1]:
2022-05-27T06:07:55.790022+00:00 app[web.1]: sh: 1: nodemon: not found
2022-05-27T06:07:55.908150+00:00 heroku[web.1]: Process exited with status 127
2022-05-27T06:07:55.963771+00:00 heroku[web.1]: State changed from starting to crashed
2022-05-27T08:04:57.623823+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/users" host=pure-hamlet-06858.herokuapp.com request_id=190b37a8-410d-4148-bc11-3194e69e9965 fwd="94.254.32.15" dyno= connect= service= status=503 bytes= protocol=https
2022-05-27T08:04:58.440005+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=pure-hamlet-06858.herokuapp.com request_id=d270eb5b-857e-4fd3-95bc-9f1195037626 fwd="94.254.32.15" dyno= connect= service= status=503 bytes= protocol=https
2022-05-27T08:04:59.403877+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/users" host=pure-hamlet-06858.herokuapp.com request_id=7dd2497f-a216-4514-87bd-4823c7ca9d55 fwd="94.254.32.15" dyno= connect= service= status=503 bytes= protocol=https
2022-05-27T08:05:00.192757+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=pure-hamlet-06858.herokuapp.com request_id=4f872a7f-4904-4589-bec3-851c39f404c0 fwd="94.254.32.15" dyno= connect= service= status=503 bytes= protocol=https
I'm guessing it has to do with this error message
heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/users" host=pure-hamlet-06858.herokuapp.com request_id=190b37a8-410d-4148-bc11-3194e69e9965 fwd="94.254.32.15" dyno= connect= service= status=503 bytes= protocol=https
I have a root folder with two subfolders backend and frontend
the root has a json file with these scripts
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node backend/server.js",
"server": "nodemon backend/server.js",
"client": "npm start --prefix frontend",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend"
},
and the backend folder has this a server file and a procfile
// Server side file, import all Routes(Views) and execute them here.
const express = require("express");
const mongoose = require("mongoose");
const dotenv = require("dotenv").config();
const PORT = process.env.PORT || 8081;
const userRouter = require("./routes/user");
const bookRouter = require("./routes/book");
const cors = require("cors");
const app = express();
app.use(express.json());
app.use(cors({ origin: "http://localhost:3000", credentials: true }));
app.use("/user", userRouter);
app.use("/book", bookRouter);
app.use("/uploads", express.static("./uploads"));
app.get("/", (req, res) => {
return res.json({ message: "Hello World 🤘" });
});
//Function to start the server
const startServer = (port) => {
try {
app.listen(port, () => {
console.log(`Server up and running at: http://localhost:${port}`);
});
} catch (error) {
console.error(error);
process.exit();
}
};
//server connection starts here
mongoose.connect(process.env.MONGODB_URI).then(() => {
startServer(PORT);
});
The Procfile
web: npm start
and in heroku a have I have the buildpacks
heroku/nodejs
https://github.com/timanovsky/subdir-heroku-buildpack.git
and also the variables
DATABASE_URL
PROJECT_PATH
My first time deploying the website I got a long error as shown below.
2020-09-25T07:31:36.727714+00:00 heroku[web.1]: State changed from starting to crashed
2020-09-25T07:31:36.730015+00:00 heroku[web.1]: State changed from crashed to starting
2020-09-25T07:31:40.230036+00:00 heroku[web.1]: Starting process with command `node server.js`
2020-09-25T07:31:43.021415+00:00 heroku[web.1]: Process exited with status 1
2020-09-25T07:31:43.061920+00:00 heroku[web.1]: State changed from starting to crashed
2020-09-25T07:31:44.106774+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=secure-coast-24568.herokuapp.com request_id=3ba32d6b-e60d-4566-8a67-bf06d6957146 fwd="116.88.43.115" dyno= connect= service= status=503 bytes= protocol=https
2020-09-25T07:31:44.535220+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=secure-coast-24568.herokuapp.com request_id=2e8669b0-19cb-43aa-90c8-1e1770aa3e6a fwd="116.88.43.115" dyno= connect= service= status=503 bytes= protocol=https
2020-09-25T07:36:38.651280+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=secure-coast-24568.herokuapp.com request_id=0d39c46b-d0d8-4bfb-9516-1c8fae89dce6 fwd="116.88.43.115" dyno= connect= service= status=503 bytes= protocol=https
2020-09-25T07:36:39.102621+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=secure-coast-24568.herokuapp.com request_id=9b23f6b1-e2ec-4f12-8b25-cb000a229675 fwd="116.88.43.115" dyno= connect= service= status=503 bytes= protocol=https
2020-09-25T07:48:16.835509+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=secure-coast-24568.herokuapp.com request_id=956d30e4-a981-48fd-9ec9-2598975d3e1d fwd="116.88.43.115" dyno= connect= service= status=503 bytes= protocol=https
2020-09-25T07:48:17.345353+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=secure-coast-24568.herokuapp.com request_id=35947874-9055-4b74-ab76-31c4329e0c72 fwd="116.88.43.115" dyno= connect= service= status=503 bytes= protocol=https
I am not sure what is the cause of the problem but there were many others too getting the same errors which was rectified. Going through what they did to fix the problem I followed the steps but still got the same error. Currently the website is working 100% when used locally and I did multiple tests before I deployed it.
This is my server.js
const dotenv = require("dotenv");
const mongoose = require("mongoose");
const app = require("./app");
app.set("view engine", "ejs");
process.on("uncaughtException", () => {
process.exit(1);
});
dotenv.config({
path: "./config.env",
});
const DB = process.env.DATABASE.replace(
"<PASSWORD>",
process.env.DATABASE_PASSWORD
);
mongoose
.connect(DB, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
})
.then(() => {
console.log("Success");
});
// Server
const port = process.env.PORT || "3000";
const server = app.listen(port, () => {
console.log("Server started");
});
// Handle all the errors in the async code that wasnt handle
process.on("unhandledRejection", () => {
server.close(() => {
process.exit(1);
});
});
My environment variables, e.g. DATABASE and DATABASE_PASSWORD, are set in a file called config.env, which is ignored via my .gitignore since it contains sensitive information.
Your config.env file should indeed be ignored. Sensitive information like your database credentials shouldn't be committed.
However, your application needs those values. On Heroku, the solution is to set config vars that get exposed to your application as environment variables. You can do this with the Heroku CLI, e.g.
heroku config:set DATABASE_PASSWORD=12345
or via the web dashboard.
Note that in most cases you shouldn't be setting database credentials manually on Heroku. Use a database addon and whatever config vars it sets, e.g. the Heroku Postgres service sets a variable called DATABASE_URL automatically.
//import modules
var builder = require("botbuilder");
var restify = require("restify");
var menu = require("./menuConfig.json");
var express = require("express");
var request = require("request");
var bodyParser = require("body-parser");
I got this part for ms-Azure connector, and builder.UniversalBot() method for the XXX.dialog() waterflow pattern.
var server = restify.createServer();
server.listen(process.env.port||process.env.PORT||3978, function () {
console.log('%s listening to %s', server.name, server.url);
})
var connector = new builder.ChatConnector({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword,
})
server.post('/api/messages', connector.listen());
var bot = new builder.UniversalBot(connector)
Then I added second part for Heroku connect and facebook webhook
var app = express();
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
app.listen((process.env.PORT||5000));
app.get("/",function(req,
res){
res.send("deployed!");
})
app.get("/webhook",function(req,res){
if(req.query["hub.verify_token"]==="process.env.VERIFICATION_TOKEN"){
console.log("Verified webhook");
res.status(200).send(req.query["hub.challenge"]);
}else{
console.error("Verification failed. The tokens do not match");
res.sendStatus(403)
}
})
var mainMenu = menu.main;
var drinkMenu = menu.drink;
var foodMenu = menu.food;
then rest dialog water flow
bot.dialog("/",[
//default dialog
function(session) {
session.send("welcom!!");
session.replaceDialog('mainMenu');
}
]).triggerAction({matches: /^fistUse$/});
.....etc
this is my package.json
{
"name": "baobao_generator_bot",
"version": "1.0.0",
"description": "create baobao generator bot",
"main": "app.js",
"author": {
"name": "orangelion"
},
"license": "ISC",
"scripts": {
"start": "node app.js"
},
"dependencies": {
"body-parser": "^1.18.2",
"botbuilder": "3.14.0",
"express": "^4.16.2",
"mongoose": "^5.0.9",
"request": "^2.83.0",
"restify": "6.3.4"
}
}
I successfully git pushed my program to heroku.
but when I enter heroku open, I got Application error.
Here's the log.
Application Logs
2018-03-07T11:18:55.690635+00:00 app[web.1]: - npm ERR! A complete log of this run can be found in:
2018-03-07T11:18:55.690851+00:00 app[web.1]: - npm ERR! /app/.npm/_logs/2018-03-07T11_18_55_626Z-debug.log
2018-03-07T11:18:55.895218+00:00 heroku[web.1]: - State changed from starting to crashed
2018-03-07T11:18:55.882087+00:00 heroku[web.1]: - Process exited with status 1
2018-03-07T11:46:32.782848+00:00 heroku[router]: - at=error code=H10 desc="App crashed" method=GET path="/" host=immense-falls-15019.herokuapp.com request_id=05e87397-b586-4319-abf6-a51deab37e7b fwd="125.227.255.81" dyno= connect= service= status=503 bytes= protocol=https
2018-03-07T11:46:33.061549+00:00 heroku[router]: - at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=immense-falls-15019.herokuapp.com request_id=5fd3502b-0884-430d-a3a8-9088ab62e2e5 fwd="125.227.255.81" dyno= connect= service= status=503 bytes= protocol=https
2018-03-07T11:47:41.678941+00:00 heroku[router]: - at=error code=H10 desc="App crashed" method=GET path="/" host=immense-falls-15019.herokuapp.com request_id=a203c6a9-b934-4306-823f-00baf6eb6f9d fwd="125.227.255.81" dyno= connect= service= status=503 bytes= protocol=https
2018-03-07T11:47:41.975202+00:00 heroku[router]: - at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=immense-falls-15019.herokuapp.com request_id=22b6bb3e-c5c0-47e6-a4c7-c5b3d1f17b0f fwd="125.227.255.81" dyno= connect= service= status=503 bytes= protocol=https
2018-03-07T11:51:02.393492+00:00 heroku[router]: - at=error code=H10 desc="App crashed" method=GET path="/" host=immense-falls-15019.herokuapp.com request_id=66493288-1511-46dc-9c58-9978ad6ed3d5 fwd="125.227.255.81" dyno= connect= service= status=503 bytes= protocol=https
2018-03-07T11:51:02.708936+00:00 heroku[router]: - at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=immense-falls-15019.herokuapp.com request_id=0f4af933-6501-4966-856a-91e77e504868 fwd="125.227.255.81" dyno= connect= service= status=503 bytes= prot
ocol=https
I've found similar quetion here but didn't get the solution of my problem.
Is there a way not too complicated to run a msbot-frame-work chatbot
on heroku? Or I have to choose : give up to use ms-bot-framework or use Azure?
And any other cloud service is recommended?
I am building a NodeJS application using express here is my code:
var express = require('express');
var app = express();
var session = require('express-session');
var uuidv1 = require('uuid/v1');
require('dotenv').config();
var APIAI_TOKEN = process.env.APIAI_TOKEN;
var APIAI_SESSION_ID = uuidv1();
app.use(express.static(__dirname + '/views')); // html
app.use(express.static(__dirname + '/public')); // js, css, images
var server = require('http').createServer(app);
var port = process.env.port || 3000;
server.listen(port, function() {
console.log('Server listening at port: ', port);
// console.log(APIAI_SESSION_ID);
// console.log(APIAI_TOKEN);
});
app.use(session({
genid: function(req) {
return APIAI_SESSION_ID;
},
secret: 'secret',
saveUninitialized: true,
resave: true
}));
var io = require('socket.io')(server);
var apiai = require('apiai')(APIAI_TOKEN);
var rp = require('request-promise');
//#region Web UI
app.get('/', function(req, res) {
res.sendFile('index.html');
});
I start my app with node app and everything works perfectly on my localhost but when I deploy the app to Google App engine i get a 502 bad gateway error and when i check the log it happens at the app.get() method.
I even deployed it to Heroku server as well, the app is crashing at the same point. What could be wrong with my code?
Here is the log form Heroku server:
2017-11-01T16:35:57.528020+00:00 heroku[router]: at=error code=H10
desc="App crashed" method=GET path="/" host=ippcbot.herokuapp.com request_id=d956df30-8352-4a54-80e6-2aa1fc96276b fwd="197.210.37.211" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T16:35:58.138751+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ippcbot.herokuapp.com request_id=96b2bf0d-df05-4d7e-9018-0b09e1dfa748 fwd="197.210.37.211" dyno= connect= service= status=503 bytes= protocol=https
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
2017-11-01T16:19:36.517868+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-11-01T16:19:36.513572+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-11-01T16:19:36.517927+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2017-11-01T16:19:36.584087+00:00 heroku[web.1]: Process exited with status 1
2017-11-01T16:19:36.607609+00:00 heroku[web.1]: State changed from starting to crashed
2017-11-01T16:20:47.248202+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ippcbot.herokuapp.com request_id=41e9f39b-e908-4cee-a430-0d7f44a17590 fwd="197.210.37.211" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T16:20:47.891459+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ippcbot.herokuapp.com request_id=9f244daf-7a3e-405e-b445-2fadd8b2735b fwd="197.210.37.211" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T16:35:13.187594+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ippcbot.herokuapp.com request_id=455ccd5e-e389-49be-b892-e5e222c9864f fwd="197.210.37.211" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T16:35:13.805998+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ippcbot.herokuapp.com request_id=112a5f08-632e-463d-b8e8-ed6de13b3596 fwd="197.210.37.211" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T16:35:57.528020+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ippcbot.herokuapp.com request_id=d956df30-8352-4a54-80e6-2aa1fc96276b fwd="197.210.37.211" dyno= connect= service= status=503 bytes= protocol=https
2017-11-01T16:35:58.138751+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ippcbot.herokuapp.com request_id=96b2bf0d-df05-4d7e-9018-0b09e1dfa748 fwd="197.210.37.211" dyno= connect= service= status=503 bytes= protocol=https
Not sure about Heroku, but for App Engine does changing the port to 8080 work?
For example:
const server = app.listen(8080, () => {
const host = server.address().address;
const port = server.address().port;
console.log(`Example app listening at http://${host}:${port}`);
});
From Run Express.js on Google App Engine Flexible Environment
I could not get my web page using node.js after deploying in heroku. I am getting the below error.
Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.
My log file content is below:
2017-07-29T12:59:20.918810+00:00 heroku[web.1]: Process exited with status 1
2017-07-29T13:00:02.740139+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=node-fgdp.herokuapp.com request_id=04e1aa35-0722-4947-a832-836884934abf fwd="223.30.48.118" dyno= connect= service= status=503 bytes= protocol=https
2017-07-29T13:00:04.519877+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=node-fgdp.herokuapp.com request_id=3ea243cd-db39-43eb-978a-c25c6682e8a0 fwd="223.30.48.118" dyno= connect= service= status=503 bytes= protocol=https
2017-07-29T13:00:25.971843+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=node-fgdp.herokuapp.com request_id=6df0d3e1-4ccf-442d-a7d4-46951fb2dfd1 fwd="223.30.48.118" dyno= connect= service= status=503 bytes= protocol=https
2017-07-29T13:00:26.328156+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=node-fgdp.herokuapp.com request_id=e69ce3b6-2b4f-4701-8313-19a5e9152669 fwd="223.30.48.118" dyno= connect= service= status=503 bytes= protocol=https
2017-07-29T13:06:18.001304+00:00 app[api]: Starting process with command `heroku run` by user subhrajyotipradhan#gmail.com
2017-07-29T13:06:19.926935+00:00 heroku[run.9255]: Awaiting client
2017-07-29T13:06:19.947866+00:00 heroku[run.9255]: Starting process with command `heroku run`
2017-07-29T13:06:20.133990+00:00 heroku[run.9255]: State changed from starting to up
2017-07-29T13:06:24.521994+00:00 heroku[run.9255]: Process exited with status 127
2017-07-29T13:06:24.533168+00:00 heroku[run.9255]: State changed from up to complete
I deployed my code into Heroku and when starts run the generated URL I am getting the above error. My code is below:
package.json:
{
"name": "FGDP",
"description": "Our sample Node to Heroku app",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "~4.14.0",
"morgan": "~1.7.0",
"body-parser": "~1.15.2",
"method-override": "~2.3.7",
"mongojs": "~2.4.0",
"crypto-js": "~3.1.8",
"express-session": "~1.14.2",
"multer":"~1.3.0",
"dotenv" : "~4.0.0"
}
}
server.js:
var express=require('express');
var morgan = require('morgan');
var http=require('http');
var bodyParser= require('body-parser');
var methodOverride = require('method-override');
var mongo = require('mongojs');
var session = require('express-session');
var multer = require('multer')
var app=module.exports=express();
var server=http.Server(app);
const dotenv = require('dotenv');
dotenv.load();
var port=process.env.PORT;
var admin=require('./route/route.js');
app.use(express.static(__dirname + '/public')); // set the static files location /public/img will be /img for users
app.use(morgan('dev')); // log every request to the console
app.use(bodyParser.urlencoded({ extended: false })) // parse application/x-www-form-urlencoded
app.use(bodyParser.json()) // parse application/json
app.use(methodOverride()); // simulate DELETE and PUT
app.use(session({secret: 'FGDPlexel',resave: true,saveUninitialized: true}));
app.get('/',function(req,res){
res.sendFile(__dirname + '/index.html');
})
var storage =multer.diskStorage({
destination: function (req, file, callback) {
callback(null, './uploads');
},
filename: function (req, file, callback) {
callback(null, file.fieldname + '-' + Date.now());
}
});
app.post('/login',admin.userlogin);
app.get('/getSessionValue',admin.getSession);
server.listen(port);
console.log("Server is running on the port"+port);
I have set the port using dotenv and the file is given below.
.env:
PORT=8989;
Here I need to run the app.
Don't use dotenv. You can set environment variables from either the CLI or from the settings tab in the heroku dashboard. Read more about it here: https://devcenter.heroku.com/articles/config-vars#setting-up-config-vars-for-a-deployed-application
According to this issue dotenv doesn't work on Heroku in production environment. Use Heroku dashboard to set environment variables.