XMLHttpRequest cannot load http://localhost:9000/api/users/list. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
--
You received this message because you are subscribed to the Google Groups "Lagom Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lagom-framework+unsubscribe@googlegroups.com.
To post to this group, send email to lagom-framework@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lagom-framework/9edf5766-8f4f-43c0-99c6-f871f142eb6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Not yet, I do not know that much about PlayFramework, it is bit complex for me.
--
You received this message because you are subscribed to the Google Groups "Lagom Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lagom-framework+unsubscribe@googlegroups.com.
To post to this group, send email to lagom-framework@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lagom-framework/5b1aee8c-2c92-4463-a9cf-db50299d8b26%40googlegroups.com.
Hello James,
Filters class can either be in the root package..." the root package of service-api or service-impl ? I have it in service-impl@Inject public Filters(CORSFilter corsFilter) {
super(corsFilter);
}the other one is@Inject public Filters(AllowedHostsFilter allowedHostsFilter) {
super(allowedHostsFilter);
}
play.filters.cors {
pathPrefixes = ["/some/path", ...]
allowedOrigins = ["http://www.example.com", ...]
allowedHttpMethods = ["GET", "POST"]
allowedHttpHeaders = ["Accept"]
preflightMaxAge = 3 days
}mistype fix :)play.filters.cors { pathPrefixes = ["/"] allowedOrigins = ["http://localhost:3000"] allowedHttpMethods = ["GET", "POST","PUT","DELETE"]
allowedHttpHeaders = ["Accept"] preflightMaxAge = 3 days }
Also I should mention that I have libraryDependencies += filters in build.sbt
Hello James,I fallowed the instruction but I still recive the same error, so my questions are:
- "The
Filtersclass can either be in the root package..." the root package of service-api or service-impl ? I have it in service-impl- also there are two .java files one is
@Inject public Filters(CORSFilter corsFilter) { super(corsFilter); }
the other one is@Inject public Filters(AllowedHostsFilter allowedHostsFilter) { super(allowedHostsFilter); }
3. Lagom does not generate "application.conf" file so I copied from seeds as it is like => path: service-impl\src\main\resources\application.conf which only contains "play.modules.enabled += com.sample.module" so here I addedplay.filters.cors { pathPrefixes = ["/some/path", ...] allowedOrigins = ["http://www.example.com", ...] allowedHttpMethods = ["GET", "POST"] allowedHttpHeaders = ["Accept"] preflightMaxAge = 3 days }
--
You received this message because you are subscribed to the Google Groups "Lagom Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lagom-framework+unsubscribe@googlegroups.com.
To post to this group, send email to lagom-framework@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lagom-framework/f147bc25-4e6c-4500-a397-6113b9f210bd%40googlegroups.com.
public class Filters implements HttpFilters {
private final EssentialFilter[] filters;
@Inject
public Filters(final CORSFilter corsFilter) {
filters = new EssentialFilter[]{corsFilter.asJava()};
}
@Override
public EssentialFilter[] filters() {
return filters;
}
}
--
You received this message because you are subscribed to the Google Groups "Lagom Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lagom-framework+unsubscribe@googlegroups.com.
To post to this group, send email to lagom-framework@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lagom-framework/59ab4331-2134-433e-8243-2eec51bb561a%40googlegroups.com.
.withCors(true)
To view this discussion on the web visit https://groups.google.com/d/msgid/lagom-framework/CABY0rKP1Hy0sVEQ4SfYN3Au-cjcsxs9wiPVcXD22M%2B_inEEtMg%40mail.gmail.com.
named("behavioral-event").withCalls(
restCall(Method.GET, "/events/log", event_sourcing)
).withAutoAcl(true).withAcls(
ServiceAcl.forMethodAndPathRegex(Method.OPTIONS, "/events/log.*")
)
import javax.inject.Inject
import play.api.http.DefaultHttpFilters
import play.filters.cors.CORSFilter
class MyFilters @Inject()(corsFilter: CORSFilter)
extends DefaultHttpFilters(corsFilter)
play.http.filters = "com.myapp.impl.MyFilters"
play.filters.cors {
# The path prefixes to filter.
pathPrefixes = ["/events/log"]
# The allowed origins. If null, all origins are allowed.
allowedOrigins = null
# The allowed HTTP methods. If null, all methods are allowed
allowedHttpMethods = null
# The allowed HTTP headers. If null, all headers are allowed.
allowedHttpHeaders = null
# The exposed headers
exposedHeaders = []
# Whether to support credentials
supportsCredentials = false
# The maximum amount of time the CORS meta data should be cached by the client
preflightMaxAge = 6 hour
}
function send_demo(myjson) {
$.ajax({
url:'http://localhost:9000/events/log',
type:'GET',
data : JSON.stringify(myjson),
dataType: 'json',
contentType: 'application/json; charset=UTF-8',
success: function(data) {
console.log(data);
},
error: function( jqXHR, textStatus, errorThrown ) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
});
}
var eventJson = {... building my event as a js object ... };
send_demo(eventJson)
--
You received this message because you are subscribed to the Google Groups "Lagom Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lagom-framework+unsubscribe@googlegroups.com.
To post to this group, send email to lagom-framework@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lagom-framework/5177de3a-312d-42b1-90f8-04ed3869d751%40googlegroups.com.
function send_demo_canal(myjson) {
$.ajax({
url:'http://localhost:9001/events/log',
type:'POST',
data : JSON.stringify(myjson),
success: function(data) {
console.log(data);
}
error: function( jqXHR, textStatus, errorThrown ) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
});
}
var eventStr = "{...building my event..}";
var eventJson = JSON.parse(eventStr);
To unsubscribe from this group and stop receiving emails from it, send an email to lagom-framewo...@googlegroups.com.
To post to this group, send email to lagom-f...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lagom-framework/5177de3a-312d-42b1-90f8-04ed3869d751%40googlegroups.com.
class MyFilters @Inject()(corsFilter: CORSFilter)
import play.filters.cors.CORSComponents// ...abstract class MyApplication(context: LagomApplicationContext)
extends LagomApplication(context)
with ...
with CORSComponents // 1) mix in{override lazy val httpFilters: Seq[EssentialFilter] = Seq(corsFilter) // 2) enable it
// other stuff for your app here...
}
lazy val `my-impl` = (project in file("my-impl"))
.enablePlugins(LagomScala)
.settings(
libraryDependencies ++= Seq(
...,
filters, // <--- this is part of PlayImport, brought in by Lagom plugin.
...
)
)
.settings(lagomForkedTestSettings: _*)
.dependsOn(`my-api`)
To unsubscribe from this group and stop receiving emails from it, send an email to lagom-framework+unsubscribe@googlegroups.com.
To post to this group, send email to lagom-framework@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lagom-framework/e6425b71-bbd0-46ba-bdd5-7cf7f4b479ab%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to lagom-framewo...@googlegroups.com.
To post to this group, send email to lagom-f...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lagom-framework/59ab4331-2134-433e-8243-2eec51bb561a%40googlegroups.com.
James - I too will hit this problem fairly soon I imagine. On this "broader discussion", given that I have upwards of 10 services by now, is it a problem enabling each for CORS? Can this cause a clash somehow or is it safe?