I tried to simply get locations of photos in my route and render product.ejs file:
//Show individual product info
router.get('/product/:id', async function(req, res, next) {
let filesFromFolder;
Promise.all([
database.retreaveImage(req.params.id)
]).then(resultArr => {
filesFromFolder = resultArr[0];
res.render('product.ejs', {
productName: req.params.id,
data: filesFromFolder
});
});
});
It works on localhost, now i importet my route.js file in real server, and when i try to open product it throws 504 error.
tried to follow this instructions but no help.
Getting 504 GATEWAY_TIMEOUT NodeJs
grep -i "504" /var/log/nginx/access.log
82.135.208.60 - - [16/Sep/2019:07:52:25 +0000] "GET /product/line_fan_pool HTTP/1.1" 504 594 "http://13.58.120.242:3000/horizontal" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
82.135.208.60 - - [16/Sep/2019:08:03:15 +0000] "GET /product/line_pool HTTP/1.1" 504 594 "http://13.58.120.242:3000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
82.135.208.60 - - [16/Sep/2019:08:10:19 +0000] "GET /product/line_pool HTTP/1.1" 504 594 "http://13.58.120.242:3000/" "Mozilla/5.0 (Linux; Android 6.0; Nexus 5Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Mobile Safari/537.36"
Problem was that, amazon web server did not support old version of MYsql so i had to update it. That solved my problem. Had to watch in pm2 monit for error.
I experienced a 504 in my node expressjs app when something broke inside my http-proxy-middleware.
It was a Promise error not catched and so the server silently timedout into the 504 instead of reporting the error.
So never forget to catch your Promises when they fall.
(Is this what happened here?)
//Show individual product info
router.get('/product/:id', async function(req, res, next) {
let filesFromFolder;
Promise.all([
database.retreaveImage(req.params.id)
]).then(resultArr => {
//...
}).catch(err => next); // catch and burn.
});
Related
I'm brand new to Node JS (v.10.9.0) and wanted to make a simple web scraping tool that gets statistics and ranks for players on this page. No matter what I can't make it work with this website, I tried multiple request methods including http.request and https.request and have gotten every method working with 'http://www.google.com'. However every attempt for this specific website either gives me a 301 error or a socket hang up error. The location the 301 error gives me is the same link but with a '/' on the end and requesting it results in a socket hang up. I know the site runs on port 443. Do some sites just block node js, why are browsers able to connect but not stuff like this?
Please don't link me to any other threads I've seen every single one and none of them have helped
var request = require('request');
var options = {
method: "GET",
uri: 'https://www.smashboards.com',
rejectUnauthorized: false,
port: '443'
};
request(options, function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:'); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the Google homepage.
});
Error:
error: { Error: socket hang up
at createHangUpError (_http_client.js:322:15)
at TLSSocket.socketOnEnd (_http_client.js:425:23)
at TLSSocket.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1085:12)
at process._tickCallback (internal/process/next_tick.js:63:19) code: 'ECONNRESET' }
EDIT:
Adding this to my options object fixed my problem
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}
OP Here
All I did was add:
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}
To my options Object and it's working perfectly.
New code:
var request = require('request');
var options = {
method: 'GET',
uri: 'https://www.smashboards.com',
rejectUnauthorized: false,
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}
};
request(options, function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:'); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the Google homepage.
});
Thats 12+ hours I'm never getting back
I have a created a local node server and when i'm printing User-Agent from req of GET request, like:
router.get('**', function (req, res, next) {
if (req.header('User-Agent')) {
console.log('user-agent = ', (req.header('User-Agent')))
res.end(req.header('User-Agent'));
} else {
res.send('Hello World!!!')
}
});
then it print different User-Agent for / path and /favicon.ico path for my One Plus device.
result:-
/ = Mozilla/5.0 (Linux; Android 8.0.0; ONEPLUS A3003 Build/OPR6.170623.013) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.109 Mobile Safari/537.36
/favicon.ico = Mozilla/5.0 (Linux; Android 8.0.0; Build/OPR6.170623.013) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.109 Mobile Safari/537.36
why these two different User-Agent is comming from same browser.
I'm testing this on Chrome browser.
I am trying to call a soap web service from node js. But the server does not show me any output either the success or the error. I am using http server for this purpose
My output is always :
[Thu Dec 15 2016 15:12:16 GMT+0530 (India Standard Time)] "GET /views/bookNGo.html?empId=EMP2&empName=ABCD&mobile=3312&alternateMobile=678&address=hjhjh&landMark=hjgjhgj&deptId=hjhj&projectId=hjgh&app
rovingManager=kjhkj&pickupPoint=jkhjkh&dropPoint=jkhjk" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"
var soap = require('soap');
console.log('One');
var url = 'https://ap2.salesforce.com/services/wsdl/class/InsertEmployee?WSDL';
var args = {"employeeId": "EMP2","employeeName": "Chandra","phoneNumber":"12345","alternatePhoneNumber": "98765","address": "Boduppal", "landMark": "Temple","departmentID": "001","projectID": "001","approvingManager": "Prashanth","pikupPoint": "Uppal","dropPoint":"Hitec"};
soap.createClient(url, function(err, client) {
client.createEmployee(args, function(err, result) {
console.log("Webservice called");
console.log(result);
});
});
I have tired running the code in https://runkit.com/npm/soap and it gives me an error saying "TypeError: Cannot read property 'InsertEmployeeService' of undefined".
var phantom = require('phantom');
console.dir(phantom);
phantom.create(function(browser){
browser.createPage(function(page){
page.customHeaders={
"HTTP_USER_AGENT": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36",
};
console.dir(page.settings);
//undefined
page.settings={};
page.settings.userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36';
page.settings.HTTP_USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36';
console.dir(page.settings);
page.open('http://example.com/req.php', function() {
setTimeout(function() {
var output = page.evaluate(function() {
return document;
});
console.dir(output);
//undefined
}, 1000);
});});});
when I use phantomjs I try and set the header for userAgent using three different ways but when I visit the page and save the PHP $_SERVER object to a txt pad I still see PhantomJS
HTTP_USER_AGENT: Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.0.1-development Safari/538.1
not only that but the output of the page is also undefined.
It seems that the docs have changed or I cant find the correct ones. I am looking at
http://phantomjs.org/api/webpage/property/settings.html
https://www.npmjs.com/package/phantom
How is this used correctly?
According to the Functional Details in the docs, you have to set the user agent through page.set():
page.set('settings.userAgent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36');
It has to be done this way, because the bridge has to communicate with the PhantomJS process and isn't doing this in a non-asynchronous fashion. This could've probably been implemented with Object.defineProperty.
If you want to set multiple settings at once, you can do (ref):
page.set('settings', {
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11",
javascriptEnabled: false,
loadImages: false
});
You can find a list of settings that you can set in page.settings.
Currently [ 27.01.2018 ], with these requirements:
phantom: ^4.0.12,
webpage: ^0.3.0
i use this method to set up this property:
page.setting(key, value);
I checked it out with php in $_SERVER array. It works correctly.
Сompletely code looks like this:
const phantom = require('phantom');
(async function() {
const instance = await phantom.create();
const page = await instance.createPage();
page.setting('userAgent',"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11");
await page.on('onResourceRequested', function(requestData) {
//Dump request settings to view result of our changes:
console.info('Requesting', requestData);
});
const status = await page.open('https://stackoverflow.com');
const content = await page.property('content');
//console.log(content);
await instance.exit();
})();
Using mongoose to connect to mongolab and hosted in heroku. Method get, post , put works perfectly but deleting is the "problem".
when i tried to delete. i got it first.
Request URL:https://---------.herokuapp.com/------/54b413c2647bec02001efdd0
Request Headers
Provisional headers are shown
Accept:application/json, text/plain, */*
Origin:null
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/39.0.2171.95 Safari/537.36
After 30 seconds more or less i got this.
Remote Address:150.100.2.200:8080
Request URL:https://---------.herokuapp.com/------/54b413c2647bec02001efdd0
Request Method:DELETE
Status Code:503 Service Unavailable
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8,es-419;q=0.6,es;q=0.4,fr;q=0.2
Host:-----.herokuapp.com
Origin:null
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/39.0.2171.95 Safari/537.36
Response Headersview source
Cache-Control:no-cache, no-store
Connection:keep-alive
Content-Length:484
Content-Type:text/html; charset=utf-8
Date:Mon, 12 Jan 2015 20:36:33 GMT
Server:Cowboy
I have this. Showing me an error 503 but.. if i chek on mongolab webpage the item is already gone. When i tested it in my local machine everything works fine including delete method but using heroku i got this problem.
-CORS avaliable.
-These are 3 different ways that i tried to do obtaining the same result.
exports.deleteNotificacion = function(req, res) {
var id = req.params.id;
console.log(id);
Todo.findById(id,function(err,notificacion){
notificacion.remove();
notificacion.save();
}); }
exports.deleteNotificacion = function(req, res) {
var id = req.params.id;
console.log(id);
Todo.findById(id,function(err,notificacion){
notificacion.remove (function(err){
if (!err) {
res.send('');
console.log('Removed');
}else {
console.log('ERROR: ' + err);
};
})
}); }
exports.deleteNotificacion = function(req, res) {
var id = req.params.id;
console.log(id);
Todo.findByIdAndRemove(id,function(err){
if(err){console.log("ERROR " + err);}
// res.send("eliminado");
});}
Code samples that you have posted are difficult to read, but it seems that you just don't send anything to the client if the request was successful. After 30s of waiting Heroku router timeouts and your client get a 503 page, as described in this blogpost.
One of the correct responses to a DELETE request is to send HTTP 204 code with no body:
res.status(204).end();