'+ escapeHtml(title) + '
' + escapeHtml(summary) +'
diff --git a/index.html b/index.html new file mode 100644 index 0000000..3576cda --- /dev/null +++ b/index.html @@ -0,0 +1,361 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +DotKernel's middleware for setting and overwriting custom response headers.
+ + +
+
+ $ composer require dotkernel/dot-response-header
+
+
+
+++ +Go to homepage + + +Something went wrong!
++ We're sorry, but the page you are looking for does not exist. +
+
' + escapeHtml(summary) +'
' + noResultsText + '
'); + } +} + +function doSearch () { + var query = document.getElementById('mkdocs-search-query').value; + if (query.length > min_search_length) { + if (!window.Worker) { + displayResults(search(query)); + } else { + searchWorker.postMessage({query: query}); + } + } else { + // Clear results for short queries + displayResults([]); + } +} + +function initSearch () { + var search_input = document.getElementById('mkdocs-search-query'); + if (search_input) { + search_input.addEventListener("keyup", doSearch); + } + var term = getSearchTermFromLocation(); + if (term) { + search_input.value = term; + doSearch(); + } +} + +function onWorkerMessage (e) { + if (e.data.allowSearch) { + initSearch(); + } else if (e.data.results) { + var results = e.data.results; + displayResults(results); + } else if (e.data.config) { + min_search_length = e.data.config.min_search_length-1; + } +} + +if (!window.Worker) { + console.log('Web Worker API not supported'); + // load index in main thread + $.getScript(joinUrl(base_url, "search/worker.js")).done(function () { + console.log('Loaded worker'); + init(); + window.postMessage = function (msg) { + onWorkerMessage({data: msg}); + }; + }).fail(function (jqxhr, settings, exception) { + console.error('Could not load worker.js'); + }); +} else { + // Wrap search in a web worker + var searchWorker = new Worker(joinUrl(base_url, "search/worker.js")); + searchWorker.postMessage({init: true}); + searchWorker.onmessage = onWorkerMessage; +} diff --git a/search/search_index.json b/search/search_index.json new file mode 100644 index 0000000..b9f74be --- /dev/null +++ b/search/search_index.json @@ -0,0 +1 @@ +{"config":{"indexing":"full","lang":["en"],"min_search_length":3,"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"../../README.md","title":"Home"},{"location":"v3/configuration/","text":"Configuration Requirements PHP >= 8.1 Register ConfigProvider Next, register the package's ConfigProvider to your application config. Dot\\ResponseHeader\\ConfigProvider::class, Note : Make sure to register the package under the // DK packages section. Add the package to the middleware stack After registering the package, add it to the middleware stack in config/pipeline.php after $app->pipe(RouteMiddleware::class); $app->pipe(RouteMiddleware::class); $app->pipe(\\Dot\\ResponseHeader\\Middleware\\ResponseHeaderMiddleware::class); Add configuration in autoload Create a new file response-header.global.php in config/autoload with the below configuration array : <?php return [ 'dot_response_headers' => [ '*' => [ 'CustomHeader1' => [ 'value' => 'CustomHeader1-Value', 'overwrite' => true, ], 'CustomHeader2' => [ 'value' => 'CustomHeader2-Value', 'overwrite' => false, ], ], 'home' => [ 'CustomHeader' => [ 'value' => 'header3', ] ], 'login' => [ 'LoginHeader' => [ 'value' => 'LoginHeader-Value', 'overwrite' => false ] ], ] ];","title":"Configuration"},{"location":"v3/configuration/#configuration","text":"","title":"Configuration"},{"location":"v3/configuration/#requirements","text":"PHP >= 8.1","title":"Requirements"},{"location":"v3/configuration/#register-configprovider","text":"Next, register the package's ConfigProvider to your application config. Dot\\ResponseHeader\\ConfigProvider::class, Note : Make sure to register the package under the // DK packages section.","title":"Register ConfigProvider"},{"location":"v3/configuration/#add-the-package-to-the-middleware-stack","text":"After registering the package, add it to the middleware stack in config/pipeline.php after $app->pipe(RouteMiddleware::class); $app->pipe(RouteMiddleware::class); $app->pipe(\\Dot\\ResponseHeader\\Middleware\\ResponseHeaderMiddleware::class);","title":"Add the package to the middleware stack"},{"location":"v3/configuration/#add-configuration-in-autoload","text":"Create a new file response-header.global.php in config/autoload with the below configuration array : <?php return [ 'dot_response_headers' => [ '*' => [ 'CustomHeader1' => [ 'value' => 'CustomHeader1-Value', 'overwrite' => true, ], 'CustomHeader2' => [ 'value' => 'CustomHeader2-Value', 'overwrite' => false, ], ], 'home' => [ 'CustomHeader' => [ 'value' => 'header3', ] ], 'login' => [ 'LoginHeader' => [ 'value' => 'LoginHeader-Value', 'overwrite' => false ] ], ] ];","title":"Add configuration in autoload"},{"location":"v3/installation/","text":"Installation Install dotkernel/dot-response-header by executing the following Composer command in your project directory: composer require dotkernel/dot-response-header","title":"Installation"},{"location":"v3/installation/#installation","text":"Install dotkernel/dot-response-header by executing the following Composer command in your project directory: composer require dotkernel/dot-response-header","title":"Installation"},{"location":"v3/overview/","text":"Overview dot-response-header is DotKernel's middleware for setting and overwriting custom response headers.","title":"Overview"},{"location":"v3/overview/#overview","text":"dot-response-header is DotKernel's middleware for setting and overwriting custom response headers.","title":"Overview"},{"location":"v3/usage/","text":"Usage Because headers are matched with route names, we can have custom response headers for every request, by defining new headers under the * key, in the configuration file response-header.global.php . All headers under * will be set for every response. To add response headers for a specific set of routes, define a new array using the route name as the array key. Example 'dot_response_headers' => [ 'user' => [ 'UserCustomHeader' => [ 'value' => 'UserCustomHeader-Value', 'overwrite' => false ] ], ] // This will set a new header named UserCustomHeader with the UserCustomHeader-Value value for any route name matching 'user' To overwrite an existing header use overwrite => true .","title":"Usage"},{"location":"v3/usage/#usage","text":"Because headers are matched with route names, we can have custom response headers for every request, by defining new headers under the * key, in the configuration file response-header.global.php . All headers under * will be set for every response. To add response headers for a specific set of routes, define a new array using the route name as the array key.","title":"Usage"},{"location":"v3/usage/#example","text":"'dot_response_headers' => [ 'user' => [ 'UserCustomHeader' => [ 'value' => 'UserCustomHeader-Value', 'overwrite' => false ] ], ] // This will set a new header named UserCustomHeader with the UserCustomHeader-Value value for any route name matching 'user' To overwrite an existing header use overwrite => true .","title":"Example"}]} \ No newline at end of file diff --git a/search/worker.js b/search/worker.js new file mode 100644 index 0000000..8628dbc --- /dev/null +++ b/search/worker.js @@ -0,0 +1,133 @@ +var base_path = 'function' === typeof importScripts ? '.' : '/search/'; +var allowSearch = false; +var index; +var documents = {}; +var lang = ['en']; +var data; + +function getScript(script, callback) { + console.log('Loading script: ' + script); + $.getScript(base_path + script).done(function () { + callback(); + }).fail(function (jqxhr, settings, exception) { + console.log('Error: ' + exception); + }); +} + +function getScriptsInOrder(scripts, callback) { + if (scripts.length === 0) { + callback(); + return; + } + getScript(scripts[0], function() { + getScriptsInOrder(scripts.slice(1), callback); + }); +} + +function loadScripts(urls, callback) { + if( 'function' === typeof importScripts ) { + importScripts.apply(null, urls); + callback(); + } else { + getScriptsInOrder(urls, callback); + } +} + +function onJSONLoaded () { + data = JSON.parse(this.responseText); + var scriptsToLoad = ['lunr.js']; + if (data.config && data.config.lang && data.config.lang.length) { + lang = data.config.lang; + } + if (lang.length > 1 || lang[0] !== "en") { + scriptsToLoad.push('lunr.stemmer.support.js'); + if (lang.length > 1) { + scriptsToLoad.push('lunr.multi.js'); + } + if (lang.includes("ja") || lang.includes("jp")) { + scriptsToLoad.push('tinyseg.js'); + } + for (var i=0; i < lang.length; i++) { + if (lang[i] != 'en') { + scriptsToLoad.push(['lunr', lang[i], 'js'].join('.')); + } + } + } + loadScripts(scriptsToLoad, onScriptsLoaded); +} + +function onScriptsLoaded () { + console.log('All search scripts loaded, building Lunr index...'); + if (data.config && data.config.separator && data.config.separator.length) { + lunr.tokenizer.separator = new RegExp(data.config.separator); + } + + if (data.index) { + index = lunr.Index.load(data.index); + data.docs.forEach(function (doc) { + documents[doc.location] = doc; + }); + console.log('Lunr pre-built index loaded, search ready'); + } else { + index = lunr(function () { + if (lang.length === 1 && lang[0] !== "en" && lunr[lang[0]]) { + this.use(lunr[lang[0]]); + } else if (lang.length > 1) { + this.use(lunr.multiLanguage.apply(null, lang)); // spread operator not supported in all browsers: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator#Browser_compatibility + } + this.field('title'); + this.field('text'); + this.ref('location'); + + for (var i=0; i < data.docs.length; i++) { + var doc = data.docs[i]; + this.add(doc); + documents[doc.location] = doc; + } + }); + console.log('Lunr index built, search ready'); + } + allowSearch = true; + postMessage({config: data.config}); + postMessage({allowSearch: allowSearch}); +} + +function init () { + var oReq = new XMLHttpRequest(); + oReq.addEventListener("load", onJSONLoaded); + var index_path = base_path + '/search_index.json'; + if( 'function' === typeof importScripts ){ + index_path = 'search_index.json'; + } + oReq.open("GET", index_path); + oReq.send(); +} + +function search (query) { + if (!allowSearch) { + console.error('Assets for search still loading'); + return; + } + + var resultDocuments = []; + var results = index.search(query); + for (var i=0; i < results.length; i++){ + var result = results[i]; + doc = documents[result.ref]; + doc.summary = doc.text.substring(0, 200); + resultDocuments.push(doc); + } + return resultDocuments; +} + +if( 'function' === typeof importScripts ) { + onmessage = function (e) { + if (e.data.init) { + init(); + } else if (e.data.query) { + postMessage({ results: search(e.data.query) }); + } else { + console.error("Worker - Unrecognized message: " + e); + } + }; +} diff --git a/sitemap.xml b/sitemap.xml new file mode 100644 index 0000000..37a4b8a --- /dev/null +++ b/sitemap.xml @@ -0,0 +1,28 @@ + +Next, register the package's ConfigProvider
to your application config.
Dot\ResponseHeader\ConfigProvider::class,
+Note : Make sure to register the package under the // DK packages
section.
After registering the package, add it to the middleware stack in config/pipeline.php
after $app->pipe(RouteMiddleware::class);
$app->pipe(RouteMiddleware::class);
+$app->pipe(\Dot\ResponseHeader\Middleware\ResponseHeaderMiddleware::class);
+Create a new file response-header.global.php
in config/autoload
with the below configuration array :
<?php
+return [
+ 'dot_response_headers' => [
+ '*' => [
+ 'CustomHeader1' => [
+ 'value' => 'CustomHeader1-Value',
+ 'overwrite' => true,
+ ],
+ 'CustomHeader2' => [
+ 'value' => 'CustomHeader2-Value',
+ 'overwrite' => false,
+ ],
+ ],
+ 'home' => [
+ 'CustomHeader' => [
+ 'value' => 'header3',
+ ]
+ ],
+ 'login' => [
+ 'LoginHeader' => [
+ 'value' => 'LoginHeader-Value',
+ 'overwrite' => false
+ ]
+ ],
+ ]
+];
+
+
+
+
+
+
+
+
+
+ Install dotkernel/dot-response-header by executing the following Composer command in your project directory:
+composer require dotkernel/dot-response-header
+
+
+
+
+
+
+
+
+
+
+ dot-response-header
is DotKernel's middleware for setting and overwriting custom response headers.
Because headers are matched with route names, we can have custom response headers for every request, by defining new headers under the *
key, in the configuration file response-header.global.php
.
All headers under *
will be set for every response.
To add response headers for a specific set of routes, define a new array using the route name as the array key.
+'dot_response_headers' => [
+ 'user' => [
+ 'UserCustomHeader' => [
+ 'value' => 'UserCustomHeader-Value',
+ 'overwrite' => false
+ ]
+ ],
+]
+
+// This will set a new header named UserCustomHeader with the UserCustomHeader-Value value for any route name matching 'user'
+To overwrite an existing header use overwrite => true
.