Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem deploying projects #2

Closed
drachenminister opened this issue Aug 30, 2016 · 8 comments
Closed

problem deploying projects #2

drachenminister opened this issue Aug 30, 2016 · 8 comments

Comments

@drachenminister
Copy link
Contributor

If you are not running Node-Red stand alone on standard port 1880, but (as in my case) embedded in an existing express app on a different port (8080) then the server crashes when trying to deploy a project.

events.js:141
      throw er; // Unhandled 'error' event

There is a section of code in multiproject.js starting at line 132 where host, port, and path are hard-coded.

            var options = {
                host: "localhost",
                path: '/flows',
                port: '1880',
                headers: {
                    "node-red-deployment-type": "full",
                    "cache-control": "no-cache",
                    "content-type": "application/json; charset=utf-8"

                },
                method: 'POST'
            };

Changing only the port to 8080 gets rid of the crashes but still deploying a project dosen't seem to save it as i get the following error once I select it afterwards:

TypeError: Cannot read property 'flows' of undefined
    at /home/pi/.node-red/node_modules/node-red-contrib-multiproject/multiproject/multiproject.js:44:17
@valdepeace
Copy link
Owner

hi, i change default hostname and port to request headers. Redirect correctly now:

urlParse=require('url')
...........
           // hostname and port of header request object
            var url=urlParse.parse(req.headers.origin)
            var options = {
                host: url.hostname,
                path: '/flows',
                port: url.port,
                headers: {
                    "node-red-deployment-type":"full",
                    "cache-control": "no-cache",
                    "content-type": "application/json; charset=utf-8"
                },
                method: 'POST'
            };

@drachenminister
Copy link
Contributor Author

drachenminister commented Aug 31, 2016

I am afraid this does not work for me as req.headers.origin is undefined if for instance using Firefox 47.0.1 and therefor urlParse.parse throws an error and the server crashes.
This happens when running standalone aswell.

If I use

var options = {
    host: '<myIP>',
    path: '/flows',
    port: '<myPort>',

everything works fine running standallone and i even can access already saved projects once I switch back to running embedded. But I cannot save anything (node or project) running embedded. Allthough hitting deploy brings "Sucessfully deployed", once I reload the page in the Browser the changes are gone.

I guess there is still something wrong with the path parameter as I can put in there what I want as long as its starts with a Slash without creating any error neither on the console nor in the Browser.

As in my embedded configuration httpAdmin is served from :/red I also tried setting path to '/red/flows' to no avail.

thanks for any suggestions

@drachenminister
Copy link
Contributor Author

drachenminister commented Aug 31, 2016

Analysing some more I think the issue not being able to save is an authentication problem.

In my tests I had no authentication set when running stand-alone versus adminAuth settings when running embeded.

When I turn on the same authentication in stand-alone mode things fail the same way and when I try to directly access <myIP>:<myPort>/flows (as http.request does) I get an "unauthorised" response back instead of the JSON-representation of the flows I get without using authentication.
Maybe there is some way to rewrite that part using RED.httpAdmin.post("/flows", ...)

@valdepeace
Copy link
Owner

I'm sorry, not test in mozilla and ie, you are right,param req.headers.origin alone in chrome, no exists in mozilla and ie, though param host exist in three navigator:

var url=req.headers.host.split(":")
            var options = {
                host: url[0],
                path: '/flows',
                port: url[1],
                headers: {
                    "node-red-deployment-type":"full",
                    "cache-control": "no-cache",
                    "content-type": "application/json; charset=utf-8"

                },
                method: 'POST'
            };

The auth had not comtemplated now, the app i'm developing still have not gotten to the part of authorization, but i have already taken advantage of to make:

if(req.headers.authorization)
                options.headers.authorization=req.headers.authorization

as middleware(express) permission in red/api/auth/index.js function needsPermisssion needs request.headers.authorization inject authorization of the new request to /flows.

I have corrected the redirect and authorization to record the flows, version 0.0.2-13.

Thank you for helping me and catch these bugs.

@drachenminister
Copy link
Contributor Author

drachenminister commented Sep 1, 2016

You're welcome!

Latest fix works well in a fresh instance (one without any existing tabs or nodes) both stand-alone and embeded - only thing I had to do was to change path to path: '/red/flows/', maybe one could use referrer instead of host, which in my case shows "http://192.168.10.111:8080/red/" or one could use RED.settings.httpAdminRoot + "/flows"

If however I install the module on my existing instance with two tabs and over a hundred nodes in the flows and subflows it messes up big time mixing up projects with existing tabs.

anyway nice work so far - please let me know if you need some more information or testing.

@drachenminister
Copy link
Contributor Author

drachenminister commented Sep 1, 2016

just tested

var url=req.headers.host.split(":")
            var options = {
                host: url[0],
                path: RED.settings.httpAdminRoot + '/flows',
                port: url[1],
                headers: {
                    "node-red-deployment-type":"full",
                    "cache-control": "no-cache",
                    "content-type": "application/json; charset=utf-8"

                },
                method: 'POST'
            };

and works fine for me see #3

@drachenminister drachenminister changed the title Server crashes on full deploy problem deploying projects Sep 1, 2016
@valdepeace
Copy link
Owner

Correctly:

path: (RED.settings.httpAdminRoot==="/")?'/flows':RED.settings.httpAdminRoot+'/flows',

as httpAdminRoot defualt "/" so that path="//flows" not working apirest.

I also corrected response of "flows" when there are error redirect to client:

var callback = function(response) {
                var str = ''
                response.on('data', function (chunk) {
                    str += chunk;
                });

                response.on('end', function () {
                    res.status(this.statusCode).end(str)
                });

            }

note: install for npm use node-red-contrib-multiproject@version, npm not install version corretly. I have to see why.

npm install [email protected] --save

how to save flows in instance(file/mysql/mongo....)?

@drachenminister
Copy link
Contributor Author

I allway install using npm install https://github.com/Negrero/node-red-contrib-multiproject to get the latest version.

Latest fix works fine for me - so you might as well consider closing this issue.

As for getting my existing flows into a project I tried exporting and then re-importing it into a project and thereby ran into issue #4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants