eea.searchserver.js
Node.js search server library for EEA search apps
To be used with an express Node.js application
Features
- Proxy for any Elastic backend (so Elastic doesn't have to be exposed publicly)
- EEA Template Invalidation Routines
- Automatic template loading if templates do not exist locally
- On demand template loading via routes or util function
- API for Elastic management commands
- Framework for easily adding index management commands
- Entrypoint for any of EEA's Elastic Search Docker applications
Install
npm install eea-searchserver
Contents
Server
Initial setup
Start by writing the base configurtion file:
"http": "port": 8080 // Port on which the app will listen, default(3000) "elastic": // Remote Elastic Endpoint configuration "host": "my-elastic-host" // Host running an Elastic Server (required) "path": "/elastic/" // Path on host to the Elastic Server (default /) "port": 80 // Port on which Elastic listens (default 9200) "index": "data" // Index to be queried (required) "type": "resource" // Type to be queried (required) "external_templates": // External template service (optional) "local_path": "/path/to/external_templates" // Path to save external templates locally "host": "www.eea.europa.eu" // Host to query for external templates "head_path": // Path on host for the page HEAD "/templates/v2/getRequiredHead?jsdisable=all" "header_path": // Path on host for the page HEADER "/templates/v2/getHeader?jsdisable=all" "footer_path": // Path on host for the page FOOTER "/templates/v2/getFooter"
Running a simple express app
var eeasearch = ;// create a base appvar app = ;...// load app settingsvar settingsFile = '/path/to/settings.json';// create serverserver = eeasearch// start the appserver
Easy to add management commands:
var eeasearch = ;// create a base appvar app = ;...// add management commandsapp;// load app settingsvar settingsFile = '/path/to/settings.json';// create serverserver = eeasearch// start the appserver
Routes
Invalidate Templates
Any POST request to invalidate_templates
will get the templates from
the host which was set up in the settings.json
file and save them to the
local path.
var app = ;app;
Elastic Proxy
Any GET request with the parameter source
set as a valid Elastic query
or Any POST request with the body an valid Elastic query will be forwarded
to the Elastic host set up in the settings.json
file.
The queries will be carried out to the index and type configured in
settings.json
.
var app = ;app;
Middleware
Automatic template loading
Use this to load templates automatically on the first request on the app. This will ensure that the external templates exist on disk before rendering the page.
var app=;app;
Util
On demand template loading
This will send requests and update the external templates using the
configuration in settings.json
eeasearchutil
esAPI
A lightweight REST api for Elastic index management commands. To chain the commands use chained calls like in the following example. Otherwise, the order of the requests is asynchronous.
The REST calls are executed when .execute()
is called. If any error
occurs while executing a request, the others are not run.
Note:. This API does not use settings.json
configured Elastic host
Note:. A successful run means any response from the server (500, 200, etc.)
var options = "es_host": "http://host:port/path/to/endpoint" "auth": "user": user "pass": pass # optional if elastic needs auth ;