This Express Middleware is a bridge between a PL/SQL application running in an Oracle Database and an Express web server for Node.js. It is an open-source alternative to mod_plsql, the Embedded PL/SQL Gateway and ORDS, allowing you to develop PL/SQL web applications using the PL/SQL Web Toolkit (OWA) and Oracle Application Express (Apex), and serve the content using the Express web framework for Node.js.
Please feel free to try and suggest any improvements. Your thoughts and ideas are most welcome.
See the changelog.
The connection to the Oracle Database uses the node-oracledb Driver for Oracle Database. Please visit the node-oracledb documentation for more information.
- Create and move to a new directory
- Create a new npm project (
npm i) - Install package (
npm i --omit=dev web_plsql)
- Change to the
examples/sqldirectory, start SQLPLus, connect to the database as SYS specifying the SYSDBA roleInstall and install the sample schema@examples/sql/install.sql. - Start server using
node examples/config-native.jsafter having set the WEB_PLSQL_ORACLE_SERVER environment variable to the database where you just installed the sample schema. - Invoke a browser and open the page
http://localhost/sample.
- Build the image using
npm run image-build. - Adapt the
examples/config-docker.jsonconfiguration file. Typically only theconnectStringproperty must be changed. - Start the container using
docker compose up -d.
There are 2 options on how to use the web_plsql express middleware:
- Use the predefined
startServerapi insrc/server.jslike in theexamples/config-native.jsexample - Hand craft a new Express server using the
handlerWebPlSqlmiddleware insrc/handlerPlSql.js
The startServer api uses the following configuration object:
/**
* @typedef {'basic' | 'debug'} errorStyleType
*/
/**
* @typedef {object} configStaticType
* @property {string} route - The Static route path.
* @property {string} directoryPath - The Static directory.
*/
/**
* @typedef {(connection: Connection, procedure: string) => void | Promise<void>} transactionCallbackType
* @typedef {'commit' | 'rollback' | transactionCallbackType | undefined | null} transactionModeType
*/
/**
* @typedef {object} configPlSqlHandlerType
* @property {string} defaultPage - The default page.
* @property {string} [pathAlias] - The path alias.
* @property {string} [pathAliasProcedure] - The path alias.
* @property {string} documentTable - The document table.
* @property {string[]} [exclusionList] - The exclusion list.
* @property {string} [requestValidationFunction] - The request validation function.
* @property {Record<string, string>} [cgi] - The additional CGI.
* @property {transactionModeType} [transactionMode='commit'] - Specifies an optional transaction mode.
* "commit" this automatically commits any open transaction after each request. This is the defaults because this is what mod_plsql and ohs are doing.
* "rollback" this automatically rolles back any open transaction after each request.
* "transactionCallbackType" this allows to defined a custom handler as a JavaScript function.
* @property {errorStyleType} errorStyle - The error style.
*/
/**
* @typedef {object} configPlSqlConfigType
* @property {string} route - The PL/SQL route path.
* @property {string} user - The Oracle username.
* @property {string} password - The Oracle password.
* @property {string} connectString - The Oracle connect string.
*/
/**
* @typedef {configPlSqlHandlerType & configPlSqlConfigType} configPlSqlType
*/
/**
* @typedef {object} configType
* @property {number} port - The server port number.
* @property {configStaticType[]} routeStatic - The static routes.
* @property {configPlSqlType[]} routePlSql - The PL/SQL routes.
* @property {number} [uploadFileSizeLimit] - Maximum size of each uploaded file in bytes or no limit if omitted.
* @property {string} loggerFilename - name of the request logger filename or '' if not required.
*/WIP
The following mod_plsql DAD configuration translates to the configuration options as follows:
DAD
<Location /pls/sample>
SetHandler pls_handler
Order deny,allow
Allow from all
PlsqlDatabaseUsername sample
PlsqlDatabasePassword sample
PlsqlDatabaseConnectString localhost:1521/ORCL
PlsqlDefaultPage sample_pkg.pageIndex
PlsqlDocumentTablename doctable
PlsqlPathAlias myalias
PlsqlPathAliasProcedure sample_pkg.page_path_alias
PlsqlExclusionList sample_pkg.page_exclusion_list
PlsqlRequestValidationFunction sample_pkg.request_validation_function
PlsqlErrorStyle DebugStyle
PlsqlNlsLanguage AMERICAN_AMERICA.UTF8
</Location>
mod_plsql
{
port: 80,
routeStatic: [
{
route: '/static',
directoryPath: 'examples/static',
},
],
routePlSql: [
{
route: '/sample',
user: 'sample', // PlsqlDatabaseUserName
password: 'sample', // PlsqlDatabasePassword
connectString: 'localhost:1521/ORCL', // PlsqlDatabaseConnectString
defaultPage: 'sample_pkg.page_index', // PlsqlDefaultPage
documentTable: 'doctable', // PlsqlDocumentTablename
exclusionList: ['sample_pkg.page_exclusion_list'], // PlsqlExclusionList
requestValidationFunction: 'sample_pkg.request_validation_function', // PlsqlRequestValidationFunction
pathAlias: 'myalias', // PlsqlPathAlias
pathAliasProcedure: 'sample_pkg.page_path_alias', // PlsqlPathAliasProcedure
transactionMode: 'commit',
errorStyle: 'debug', // PlsqlErrorStyle
},
],
uploadFileSizeLimit: 50 * 1024 * 1024, // 50MB
loggerFilename: 'access.log', // PlsqlLogEnable and PlsqlLogDirectory
}...
- PlsqlDatabaseConnectString -> routePlSql[].connectString
- PlsqlDatabaseUserName -> routePlSql[].user
- PlsqlDatabasePassword -> routePlSql[].password
- PlsqlDefaultPage -> routePlSql[].defaultPage
- PlsqlDocumentTablename -> routePlSql[].documentTable
- PlsqlErrorStyle -> routePlSql[].errorStyle
- PlsqlLogEnable -> loggerFilename
- PlsqlLogDirectory -> loggerFilename
- PlsqlPathAlias -> routePlSql[].pathAlias
- PlsqlPathAliasProcedure -> routePlSql[].pathAliasProcedure
- Default exclusion list.
- PlsqlRequestValidationFunction -> routePlSql[].pathAliasProcedure
- PlsqlExclusionList
- Basic and custom authentication methods, based on the OWA_SEC package and custom packages.
- The option
transactionModeTypespecifies an optional transaction mode. "commit" this automatically commits any open transaction after each request. This is the defaults because this is what mod_plsql and ohs are doing. "rollback" this automatically rolles back any open transaction after each request. "transactionCallbackType" this allows to defined a custom handler as a JavaScript function.
- Support for APEX 5 or greater.
- PlsqlAlwaysDescribeProcedure
- PlsqlAfterProcedure
- PlsqlBeforeProcedure
- PlsqlCGIEnvironmentList
- PlsqlDocumentProcedure
- PlsqlDocumentPath
- PlsqlIdleSessionCleanupInterval
- PlsqlSessionCookieName
- PlsqlSessionStateManagement
- PlsqlTransferMode