express icon indicating copy to clipboard operation
express copied to clipboard

Nodejs with express: API request failed after few mins

Open avinash0 opened this issue 9 years ago • 5 comments

I have nodejs application with express middleware. Bellow is my code:

var express = require("express");
var app = express();
var bodyParser = require("body-parser");
var router = express.Router();
var cors = require('cors');
var fs = require('fs');
var https = require('https');
app.use(cors());
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({ limit: '50mb', "extended": false }));
app.use(express.static(path.join(__dirname, './demo')));
router.get("/", function (req, res) {
res.json({ "error": false, "message": "Hello World" });
});
app.use('/api', router);
var privateKey = fs.readFileSync('key.pem');
var certificate = fs.readFileSync('cert.pem');
var passphrase = 'pass';
var credentials = {key: privateKey, cert: certificate, passphrase:passphrase};
var server = https.createServer(credentials, app).listen(config.port);
server.timeout = 3600000;

When calling API from the ionic application located in the directory "demo" it works fine. But after few mins (near about 10-15 mins), API request gets failed (failed from the application). But if we reload the application or hit the API from postman/browser then it was working. Means node service is still running. But then why API calls are failing. What will be the possible errors? Please help. Thanks!

avinash0 avatar Sep 10 '17 09:09 avinash0

Hi @avinash0 are you saying it only happens when you use that ionic application? If so, can you please provide it? Also, can you provide more specific information on what exactly "API request gets failed" means?

dougwilson avatar Sep 10 '17 17:09 dougwilson

When calling API from the application, it works fine. But after 9-10 mins API gets failed. API failed means the status is failed in browsers network tab and returns nothing. As it is failed, the API get highlighted in red color.

avinash0 avatar Sep 11 '17 11:09 avinash0

Hi @avinash0 I'm not really sure. Can you provide the specific steps I need to perform to see the error with the code you provided?

dougwilson avatar Sep 22 '17 01:09 dougwilson

@avinash0 may be it can be helpful if you can give out server logs, May be your server shuts down, or resource doesnt respond, I unable to make much sense out of the code you have provided.

muhammadfaizan avatar Oct 19 '17 05:10 muhammadfaizan

I'm going to close this as it has been a few months.

dougwilson avatar Dec 17 '17 18:12 dougwilson