Connect oracle from nodejs

后端 未结 4 1792
既然无缘
既然无缘 2021-01-14 00:11

Last few weeks I had been trying to connect oracle db from my nodejs code. What I found so far are 2 main libraries such as https://github.com/mariano/node-db-oracle which i

4条回答
  •  失恋的感觉
    2021-01-14 01:00

    I know this is an old post... just wanted to mention a sure way for nodejs to communicate to oracle without extra modules.

    Set up oracle so it can create and receive http requests. There are a few ways to do this:

    The easiest is to turn on the epg gateway:

    • http://www.oracle-base.com/articles/10g/dbms_epg_10gR2.php

    Also you can setup modplsq:

    • http://www.comp.dit.ie/btierney/oracle11gdoc/appdev.111/b28424/adfns_web.htm

    or the Apex listener:

    • http://www.oracle.com/technetwork/developer-tools/apex-listener/overview/index.html?ssSourceSiteId=otnpt

    Then in node js do a standard http.get:

    http.get("http://localhost/accessor/myschema.my_procedure?x=1&y=2", function(res) {
        console.log("Got response: " + res.statusCode);
    }).on('error', function(e) {
       console.log("Got error: " + e.message);
    

    });

    Whichever approach...secure oracle so that it will only respond to the ip address of the nodejs server. So if running on localhost:

    if owa_util.get_cgi_env('REMOTE_ADDR') = '127.0.0.1' then 
       --ok
    else
       -- fail
    end if;
    

    Also block calls to every other package and procedure. There are few ways to do this depending on the path you take.

    Make sure you do this at a minimum:

    • create a white list of items which can be called from the web
    • require that all urls contain the schema name such as: myuser.myprocedure
    • make sure the first portion of the url (up to the query path) contains a-z 0-9 only
    • really a good white list will take care of most of these items

    There you have it...no need to worry if a module will break or stop working with the next release.

    AND...you can easily communicate from Oracle to Node use:

    • apex_web_service.make_rest_request
    • utl_http

提交回复
热议问题