Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable CORS requests for REPLGridServer #2832

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<properties>
<skip.yarn>false</skip.yarn>
<repl.web-application.version>11.37.0</repl.web-application.version>
<repl.web-application.version>11.42.0</repl.web-application.version>
<repl.web-application.url>${npm.registry.url}/@finos/legend-application-repl-deployment/-/legend-application-repl-deployment-${repl.web-application.version}.tgz</repl.web-application.url>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.net.httpserver.Headers;
import org.eclipse.collections.api.RichIterable;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
Expand Down Expand Up @@ -118,6 +119,7 @@ public void initializeServer() throws Exception
@Override
public void handle(HttpExchange exchange) throws IOException
{
handleCORS(exchange);
if ("GET".equals(exchange.getRequestMethod()))
{
try
Expand All @@ -143,6 +145,7 @@ public void handle(HttpExchange exchange) throws IOException
@Override
public void handle(HttpExchange exchange) throws IOException
{
handleCORS(exchange);
if ("GET".equals(exchange.getRequestMethod()))
{
try
Expand Down Expand Up @@ -172,6 +175,7 @@ public void handle(HttpExchange exchange) throws IOException
@Override
public void handle(HttpExchange exchange) throws IOException
{
handleCORS(exchange);
if ("GET".equals(exchange.getRequestMethod()))
{
try
Expand All @@ -195,6 +199,7 @@ public void handle(HttpExchange exchange) throws IOException
@Override
public void handle(HttpExchange exchange) throws IOException
{
handleCORS(exchange);
if ("POST".equals(exchange.getRequestMethod()))
{
try
Expand Down Expand Up @@ -226,6 +231,7 @@ public void handle(HttpExchange exchange) throws IOException
@Override
public void handle(HttpExchange exchange) throws IOException
{
handleCORS(exchange);
if ("POST".equals(exchange.getRequestMethod()))
{
try
Expand Down Expand Up @@ -257,6 +263,7 @@ public void handle(HttpExchange exchange) throws IOException
@Override
public void handle(HttpExchange exchange) throws IOException
{
handleCORS(exchange);
if ("POST".equals(exchange.getRequestMethod()))
{
try
Expand All @@ -280,6 +287,7 @@ public void handle(HttpExchange exchange) throws IOException
@Override
public void handle(HttpExchange exchange) throws IOException
{
handleCORS(exchange);
if ("GET".equals(exchange.getRequestMethod()))
{
ValueSpecification funcBody = null;
Expand Down Expand Up @@ -429,4 +437,20 @@ private static boolean checkIfPaginationIsEnabled(String queryParamsString)
}
return queryParams.get("isPaginationEnabled").equals("true") ? true : false;
}
}

private static void handleCORS(HttpExchange exchange) throws IOException
{
Headers headers = exchange.getResponseHeaders();
headers.add("Access-Control-Allow-Origin", "http://localhost:9005");
headers.add("allowedMethods", "GET, POST, OPTIONS");
headers.add("Access-Control-Allow-Credentials", "true");
headers.add("allowedTimingOrigins", "true");
headers.add("chainPreflight", "false");
headers.add("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");

if ("OPTIONS".equals(exchange.getRequestMethod()))
{
exchange.sendResponseHeaders(204, -1);
}
}
}