Configuring EWD to work with mg_web on YottaDB

93 views
Skip to the first unread message

rtweed

unread,
16 Jul 2022, 09:24:5816/07/2022
to Enterprise Web Developer Community
Chris has deprecated our old MGWSI gateway for GT.M and replaced it with his more modern mg_web interface: 

https://github.com/chrisemunt/mg_web

We recommend all users of MGWSI to migrate to mg_web, particularly if you're experiencing scalability issues.

Whilst mg_web was originally designed for modern REST-style back-ends, it can be used with older-style "server-side" technologies such as EWD, where the web pages are generated dynamically in server-side M code.  However, you need to be aware that if you're using YottaDB,  in order to capture and stream the content generated by the M WRITE commands, mg_web can ONLY be used over a networked connection to the YottaDB database.

So let me quickly run through the key configuration steps you need to make in order to use EWD with YottaDB via mg_web.

mg_web is installed as an extension to your web server (Apache or NGINX).  Read the relevant chapters (2.2 or 2.3 for Apache and NGINX respectively) in Chris's mg_web documentation.  See:


Next, I'd recommend you use Chris's new Superserver code for YottaDB - this is a lot simpler than setting up xinetd which is no longer a necessity: see Chapter 3 of his mg_web documentation - it's just a matter of installing two M routines from his MGSI repository.

So, having installed the two superserver M routines, start the superserver on YottaDB to listen on the default port 7041 using the M command:
               
                   do start^%zmgsi(0)                
           
Note: when making this call, make sure your ydb_routines environment variable (ie that defined the YottaDB M shell or run environment) includes all the routine paths where your EWD system will expect to read and write its routines (including your compiled EWD page routines)!  I came unstuck with this one and it took me a while to figure it out!

That's literally all you need to do on the YottaDB side of things.  Everything else is handled in the mg_web configuration file (mgweb.conf).


So here's the key pieces you need in your mgweb.conf file for EWD:

1) First, define a network-connected YottaDB system in the "servers" section - I'll name it "local" here but you can call it whatever you like:

<server local>
  host localhost
  tcp_port 7041
  type YottaDB
</server>

I'm assuming YottaDB is on the same server as mg_web, but it doesn't need to be - just change the host value.  I'm also specifying the superserver default port of 7041.

2) Next, it's a good idea to get mg_web to pass through a whole range of useful HTTP request name/value pairs, so add this "cgi" section to mgweb.conf:

<cgi>
  HTTP*
  AUTH_PASSWORD
  AUTH_TYPE
  CONTENT_TYPE
  GATEWAY_INTERFACE
  PATH_TRANSLATED
  REMOTE_ADDR
  REMOTE_HOST
  REMOTE_IDENT
  REMOTE_USER
  PATH_INFO
  SERVER_NAME
  SERVER_PORT
  SERVER_SOFTWARE
  SCRIPT_NAME
</cgi>

3) Next, add a "location" section to mgweb.conf for the URL path you'll use for EWD requests - I'll assume a path of /ewd:

<location /ewd>
  function ewd^%zmgewd
  servers local
</location>

4) Ok the last bit is the mg_web "shim" routine referred to above, ie ewd^%zmgewd.

So create a routine file named _zmgewd.m containing:

ewd(%CGIEVAR,%var,%sys)  ;
 new %KEY,%stream
 i $$nvpair^%zmgsis(.%KEY,$get(%CGIEVAR("QUERY_STRING")))
 i $$content^%zmgsis(.%KEY,,.%var,.%CGIEVAR)
 set %stream=$$streamascii^%zmgsis(.%sys)
 new %sys
 do nodeEntry^%zewdGTMRuntime
 quit %stream
 
mg_web will now intercept any /ewd requests and pass them to this shim code which repackages the information into the correct format for EWD's standard runtime code to use. (Thanks to Mike Clayton for this code!)

That's it, you now have all the pieces in place for mg_web to run EWD on your YottaDB server.  Compile your EWD pages and enjoy!

if you're having problems, set mg_web to generate its log which should give you a good idea of where it's going wrong.  Add this to the mgweb.conf file:

log_level eftw

Remember to restart the web server whenever you make changes to the mgweb.conf file!

In my experience, it's usually due either an mg_web configuration setting or a ydb_routines environment variable wrongly configured.


Jai Singh VistA

unread,
16 Jul 2022, 12:01:3216/07/2022
to Enterprise Web Developer Community
Hi Chris,

We request you to please help us in migrating mgwsi gateway to mg_web.
We need your extensive help in this regard.

Reply all
Reply to author
Forward
0 new messages