Difference between revisions of "Setup Precondition"

From MSX - Wiki
Jump to navigation Jump to search
(One intermediate revision by the same user not shown)
Line 91: Line 91:
== More information about CORS ==
== More information about CORS ==
For more information about CORS, please visit <span class="msx-external">https://en.wikipedia.org/wiki/Cross-origin_resource_sharing.</span>
For more information about CORS, please visit: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing.
== See also ==
== See also ==
* [[Start Object]]
* [[Start Object]]
* [[Setup Start Parameter]]
* [[Setup Start Parameter]]

Latest revision as of 09:24, 18 January 2021

You need a local or public HTTP server (e.g. Apache, nginx, Microsoft IIS, Node.js, etc.) to host your JSON files. Alternatively, you can use your NAS (Network Attached Storage) server or device that supports web server functionality. The HTTP server must support CORS (Cross-Origin Resource Sharing) to ensure that the JSON files can be loaded from each platform. This should not be a problem, because almost any HTTP server can be configured to support CORS. However, depending on the used HTTP server, the CORS support is configured differently. Please search the web for how it is done for your server. The next examples show how a basic CORS support can look like.

CORS via Apache and the .htaccess file[edit]

Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "Origin, Content-Type, Accept"
Header set Access-Control-Allow-Methods "GET, OPTIONS"

CORS via PHP[edit]

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Origin, Content-Type, Accept');
header('Access-Control-Allow-Methods: GET, OPTIONS');

CORS via Java and the HttpServlet interface[edit]

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setHeader("Access-Control-Allow-Origin", "*");
    resp.setHeader("Access-Control-Allow-Headers", "Origin, Content-Type, Accept");
    resp.setHeader("Access-Control-Allow-Methods", "GET, OPTIONS");

CORS via Node.js and the http library[edit]

const server = http.createServer((req, res) => {
    res.setHeader("Access-Control-Allow-Origin", "*");
    res.setHeader("Access-Control-Allow-Headers", "Origin, Content-Type, Accept");
    res.setHeader("Access-Control-Allow-Methods", "GET, OPTIONS");

CORS via Node.js and the http-server package[edit]

http-server --cors

CORS via Apache Tomcat and the web.xml file[edit]

<!-- ... -->
        <param-value>Origin, Content-Type, Accept</param-value>
        <param-value>GET, OPTIONS</param-value>
<!-- ... -->

CORS via Microsoft IIS and the web.config file[edit]

<!-- ... -->
    <cors enabled="true">
        <add origin="*">
                <add header="Origin" />
                <add header="Content-Type" />
                <add header="Accept" />
                <add method="GET" />
                <add method="OPTIONS" />
<!-- ... -->

More information about CORS[edit]

For more information about CORS, please visit: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing.

See also[edit]