Reputation: 305
I am a newbie developing a nodeJs application and has bundled it using browsify to a file bundle.js and want to deploy it in Nginx. I have given the reference to the bundle.js inside the index.html(shown below), which I am not sure is the right way to do. The nginx.conf file is :
server {
listen 8056;
root html/node_server;
index index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ /index.html;
}
}
The index.html file and bundle.js files are placed in htm\node_server folder and I am trying to hit port 8056 like http://localhost:8056 . But showing error :
Uncaught TypeError: Cannot read property 'prototype' of undefined in the bundle.js : 78869
in the browser console, but nothing in Nginx error log .
bundle.js : 78869 is
`/**
* Request prototype.
* @public
*/
var req = Object.create(http.IncomingMessage.prototype)`
My index.html file is :
<!doctype html>
<html>
<meta charset="utf-8">
<title>DEV</title>
<base href="/">
<body>
<script type="text/javascript" src="bundle.js"></script>
</html>
NodeJs file :
var sql = require("mssql");
var express = require('express');
var http = require("http");
var bodyParser = require('body-parser');
var jwt = require('jsonwebtoken');
var app = express();
app.use(bodyParser.json());
app.use(function (req, res, next) {
//Enabling CORS
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, contentType,Content-Type, Accept, Authorization");
next();
});
app.get('/',function(req,res){
res.send('Working');
});
Bundle.js in more detail :
`/**
* Module dependencies.
* @private
*/
var accepts = require('accepts');
var deprecate = require('depd')('express');
var isIP = require('net').isIP;
var typeis = require('type-is');
var http = require('http');
var fresh = require('fresh');
var parseRange = require('range-parser');
var parse = require('parseurl');
var proxyaddr = require('proxy-addr');
/**
* Request prototype.
* @public
*/
var req = Object.create(http.IncomingMessage.prototype) ---- Error here
/**
* Module exports.
* @public
*/
module.exports = req
/**
* Return request header.
*
* The `Referrer` header field is special-cased,
* both `Referrer` and `Referer` are interchangeable.
*
* Examples:
*
* req.get('Content-Type');
* // => "text/plain"
*
* req.get('content-type');
* // => "text/plain"
*
* req.get('Something');
* // => undefined
*
* Aliased as `req.header()`.
*
* @param {String} name
* @return {String}
* @public
*/
req.get =
req.header = function header(name) {
if (!name) {
throw new TypeError('name argument is required to req.get');
}
if (typeof name !== 'string') {
throw new TypeError('name must be a string to req.get');
}
var lc = name.toLowerCase();
switch (lc) {
case 'referer':
case 'referrer':
return this.headers.referrer
|| this.headers.referer;
default:
return this.headers[lc];
}
};
`
Am I missing something? If more details are required, kindly do comment.
Upvotes: 1
Views: 786
Reputation: 685
Wouldn't be better for you start node.js app localy on the server and than configure nginx as reverse proxy ? Here is detailed tutorial how to do it: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04
Upvotes: 0
Reputation: 1476
I deleted my previous answers, as I had misunderstood your problem.
The issue it seems is that the http
library is not suited to be browserified. In other words, there is some JavaScript in your bundle.js
file that cannot run in a web browser.
Could you give some context to the failing lines in the bundle.js
file?
This issue does not seem to have anything to do with your node.js / nginx setup.
Upvotes: 2