All Downloads are FREE. Search and download functionalities are using the official Maven repository.

assets.es-head.proxy.index.js Maven / Gradle / Ivy

Go to download

Provides a thin layer above Elasticsearch (Fluent Query API, Automatic Mapping, Utilities)

The newest version!
const http = require("http");

const CORS_SETTINGS = {
	origin: "http://localhost:9100",
	methods: "GET PUT POST DELETE OPTIONS HEAD",
	headers: "Authorization, Content-Type"
}


const recipes = {};
recipes['http-proxy'] = require("./recipes/http_proxy.js");


const clusters = [];
clusters.push( require("./clusters/localhost9200.json") );


clusters.forEach( cluster => {
	if( cluster.enabled ) {
		console.log( `creating proxy ${cluster.name}` );

		recipes[ cluster.recipe ]( cluster.settings )
			.then( function( proxy ) {
				const server = http.createServer();
				server.on('request', (req, res ) => {
					console.log( `${req.method} ${cluster.name} ${req.url}` );

					res.setHeader("Access-Control-Allow-Origin", CORS_SETTINGS.origin );
					res.setHeader("Access-Control-Allow-Methods", CORS_SETTINGS.methods );
					res.setHeader("Access-Control-Allow-Headers", CORS_SETTINGS.headers );

					if (req.method === 'OPTIONS') {
						res.writeHead(200);
						res.end();
					} else {
						proxy.request( req, res );
					}
				} );

				server.listen( cluster.bind );
				console.log( `\tlocal:  http://localhost:${cluster.bind}` );
			});
	}
});





© 2015 - 2025 Weber Informatics LLC | Privacy Policy