{"id":21614680,"url":"https://github.com/eea/eea.searchserver.js","last_synced_at":"2025-04-11T06:52:37.796Z","repository":{"id":30958980,"uuid":"34517115","full_name":"eea/eea.searchserver.js","owner":"eea","description":"Node.js search server library for EEA search apps","archived":false,"fork":false,"pushed_at":"2023-01-27T02:53:03.000Z","size":3801,"stargazers_count":2,"open_issues_count":3,"forks_count":5,"subscribers_count":44,"default_branch":"master","last_synced_at":"2025-03-23T15:17:29.685Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eea.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-24T12:20:57.000Z","updated_at":"2022-02-14T13:15:23.000Z","dependencies_parsed_at":"2023-02-15T04:31:59.917Z","dependency_job_id":null,"html_url":"https://github.com/eea/eea.searchserver.js","commit_stats":null,"previous_names":[],"tags_count":130,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eea%2Feea.searchserver.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eea%2Feea.searchserver.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eea%2Feea.searchserver.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eea%2Feea.searchserver.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eea","download_url":"https://codeload.github.com/eea/eea.searchserver.js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248358548,"owners_count":21090401,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T22:08:54.155Z","updated_at":"2025-04-11T06:52:37.763Z","avatar_url":"https://github.com/eea.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# eea.searchserver.js\nNode.js search server library for EEA search apps\n\nTo be used with an express Node.js application\n\n### Features\n* Proxy for any Elastic backend (so Elastic doesn't have to be exposed\n  publicly)\n* EEA Template Invalidation Routines\n  * Automatic template loading if templates do not exist locally\n  * On demand template loading via routes or util function\n* API for Elastic management commands\n* Framework for easily adding index management commands\n* Entrypoint for any of EEA's Elastic Search Docker applications\n\n### Install\n\n```bash\nnpm install git://github.com/eea/eea.searchserver.js\n```\n\n## Contents\n\n### Server\n#### Initial setup\nStart by writing the base configurtion file:\n\n```js\n{\n  \"http\": {\n    \"port\": 8080         // Port on which the app will listen, default(3000)\n  },\n  \"elastic\": {           // Remote Elastic Endpoint configuration\n    \"host\":\n      \"my-elastic-host\", // Host running an Elastic Server (required)\n    \"path\":\n      \"/elastic/\",       // Path on host to the Elastic Server (default /)\n    \"port\": 80,          // Port on which Elastic listens (default 9200)\n    \"index\":\n      \"data\",            // Index to be queried (required)\n    \"type\":\n      \"resource\"         // Type to be queried (required)\n  },\n  \"external_templates\": { // External template service (optional)\n    \"local_path\":\n      \"/path/to/external_templates\", // Path to save external templates locally\n    \"host\":\n      \"www.eea.europa.eu\",          // Host to query for external templates\n    \"head_path\":                    // Path on host for the page HEAD\n      \"/templates/v2/getRequiredHead?jsdisable=all\",\n    \"header_path\":                  // Path on host for the page HEADER\n      \"/templates/v2/getHeader?jsdisable=all\",\n    \"footer_path\":                  // Path on host for the page FOOTER\n      \"/templates/v2/getFooter\"\n  },\n  \"switch_condition_value_percent\": -5  // resync protection condition\n}\n```\n\n#### Running a simple express app\n\n```js\nvar eeasearch = require('eea-searchserver');\n// create a base app\nvar app = express();\n...\n// load app settings\nvar settingsFile = '/path/to/settings.json';\n// create server\nserver = eeasearch.Server(app, settingsFile)\n// start the app\nserver.run('runserver', [], function(err, server) {\n    console.log(\"Started server\");\n}\n```\n\n#### Easy to add management commands:\n\n```js\nvar eeasearch = require('eea-searchserver');\n// create a base app\nvar app = express();\n...\n// add management commands\napp.set('managementCommands', {'cmd': function(args) { console.log(args); }});\n// load app settings\nvar settingsFile = '/path/to/settings.json';\n// create server\nserver = eeasearch.Server(app, settingsFile, function(err, server) {\n    if (err) console.log(\"The app was poorly configured: \" + err.message);\n})\n// start the app\nserver.run('cmd', ['foo', 'bar'], function(err, server) {\n    if (err) {\n        console.log(\"Something went wrong when running the command\");\n    }\n    console.log(\"Ran custom command, should see ['foo', 'bar'] on screen\");\n}\n```\n\n### Routes\n#### Invalidate Templates\n\nAny POST request to ```invalidate_templates``` will get the templates from\nthe host which was set up in the ```settings.json``` file and save them to the\nlocal path.\n\n```js\nvar app = express();\napp.post('/invalidate_templates', eeasearch.routes.invalidateTemplates);\n```\n\n#### Update external configurations\n\nAny request to ```/tools/update_external_configs``` will get the latest changes\nfrom the host which was set up in the ```settings.json``` file and save them in\nelasticsearch as a cache document with _id ```externals```.\n\n#### Elastic Proxy\n\nAny GET request with the parameter ```source``` set as a valid Elastic query\nor Any POST request with the body an valid Elastic query will be forwarded\nto the Elastic host set up in the ```settings.json``` file.\n\nThe queries will be carried out to the index and type configured in\n```settings.json``` .\n\n```js\nvar app = express();\napp.post('/api', eeasearch.routes.elasticProxy);\n```\n\n### Middleware\n#### Automatic template loading\n\nUse this to load templates automatically on the first request on the app.\nThis will ensure that the external templates exist on disk before\nrendering the page.\n\n```js\nvar app=express();\napp.use(eeasearch.middleware.templateRequired);\n```\n\n### Util\n#### On demand template loading\n\nThis will send requests and update the external templates using the\nconfiguration in ```settings.json```\n\n```js\neeasearch.util.invalidateTemplates()\n```\n\n\n### esAPI\n\nA lightweight REST api for Elastic index management commands.\nTo chain the commands use chained calls like in the following example.\nOtherwise, the order of the requests is asynchronous.\n\nThe REST calls are executed when ```.execute()``` is called. If any error\noccurs while executing a request, the others are not run.\n\n__Note:__. This API does not use ```settings.json``` configured Elastic host\n__Note:__. A successful run means any response from the server (500, 200, etc.)\n\n```js\nvar options = {\n    \"es_host\": \"http://host:port/path/to/endpoint\",\n    \"auth\": {\"user\": user, \"pass\": pass} # optional if elastic needs auth\n}\nesAPI(options).DELETE(\"/index/type/_mappings\",\n                      function(err, code, header, body) {\n                        // Code can be any valid HTTP code\n                        // HTTP error codes (500, 403, ...)\n                        // are not marked as errors\n                        CallbackLogic();\n                      })\n              .PUT(\"/index/type/_mappings\",\n                      function(err, code, header, body) {\n                        OtherLogic();\n                      })\n              .execute();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feea%2Feea.searchserver.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feea%2Feea.searchserver.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feea%2Feea.searchserver.js/lists"}