I'm not clear on how to configure my applicationResources.groovy to use CDN for resources. My file looks like:
core {
dependsOn 'jquery'
// <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
resource url:'http://localhost/js/jquery.ui.touch-punch.min.js'
resource url:'http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js'
resource url:'http://localhost/js/modernizr.js'
resource url:'http://localhost/js/bootbox.min.js'
resource url:'http://localhost/js/flatui-checkbox.js'
resource url:'http://localhost/js/flatui-radio.js'
resource url:'http://localhost/js/jquery.tagsinput.js'
resource url:'http://localhost/js/jquery.placeholder.js'
resource url:'http://localhost/js/util.js'
resource url:'http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css', disposition: 'head'
resource url:'http://localhost/css/flat-ui.css', disposition: 'head'
resource url:'http://localhost/css/base.css', disposition: 'head'
}
Is there a place I can set http:// localhost one time instead of listing it over and over for each resource? My dev environment uses localhost, but production will use a cdn.
Something like:
myCDN=http://amazons3.com
resource url:???/js/myfile01.js
resource url:???/js/myfile02.js
Sure you can, The config files are .groovy and should be processed just like any other code in the application.
To do so, just put in your config closure:
def myCDN='http://amazons3.com'
resource url: myCDN + '/js/myfile01.js'
resource url: myCDN + '/js/myfile02.js'
Good luck with it.
Related
We are using connexion to serve the swagger ui. We are using the openapi 3.0.0 specification. Here is a small part of our swagger.yml:
openapi: 3.0.0
servers:
- url: /
paths:
/resource:
...
/resource2:
...
in this case the ui is served at /ui. We are however using nginx to redirect all requests to /resource into this container. We would like swagger-ui to be served at /some-subdir/ui instead of at /ui, in order to be able to redirect the requests to the right container.
trial 1
openapi: 3.0.0
servers:
- url: /app
paths:
/resource:
...
/resource2:
...
which works, except that the resources are now served at /app/resource etc, while the same resource might in the future be served by another app, so we don't want the app name to appear in the URL of the resources (while it might be acceptable just for the swagger-ui).
trial 2
I found that, when constructing the connexion app, I could specify the swagger_url option:
options = {
'swagger_url': '/app/ui'
}
connexion_app = connexion.App(__name__, specification_dir='./', options=options)
now the swagger-ui is served at /app/ui, but the ui is trying to serve /openapi.json which is not reachable since not under /app (or any other subdir).
Almost there, there is another (well hidden) option to change the path to the openapi.json, the combination with swagger_url works:
options = {
'swagger_url': '/app/ui',
'openapi_spec_path': '/app/openapi.json'
}
connexion_app = connexion.App(__name__, specification_dir='./', options=options)
I'm using Shrine with Rails to upload my images directly to S3, they are then served using Cloudfront.
My setup is working great, but I'm stuck trying to answer 2 issues:
1) User uploads a new Image via Uppy. They click "Create Image Page" which creates a new "page" object. The user is taken to a blank page, while the Image derivative is being created in a background process using Sidekiq. How can we have the image "pop-in" via JS once the derivative is successfully created and promoted to /store? Is there a callback we can pick up on, or is it possible to keep trying to find the derivative via JS until it exists?
2) Using the Derivatives Endpoint plugin, all of the image URLs are relative. Is there a way to serve this as absolute URLs from Cloudfront/Custom Domain? Here's an example using Rails:
Ruby code:
<%= image_tag(image.image_file.derivation_url(:banner, 800, 300)) %>
Resulting HTML:
<img src="/derivations/images/banner/800/300/...">
How can I instead serve this resulting URL:
<img src="http://abc123.cloudfront.net/derivations/images/banner/800/300/...">
Was this intentional to prevent DoS? Thanks.
Adding the host option to "derivation_endpoint" causes the following error returned as XML:
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>...</RequestId>
<HostId>...</HostId>
</Error>
Could this be my Cloudfront access settings? Maybe CORS.
Here is my derivation_endpoint setup in image_uploader.rb
plugin :derivation_endpoint, host: "http://abc123.cloudfront.net", prefix: "derivations", secret_key: ..., upload: true
routes.rb
mount Shrine.presign_endpoint(:cache) => "s3/params"
mount PhotoUploader.derivation_endpoint => "derivations/images"
config/initializers/Shrine.rb
Shrine.plugin :url_options, store: { host: "http://abc123.cloudfront.net" }
Since the background job will update the record with derivatives, the easiest would be to poll the "show" route of the record (i.e. GET /images/:id) on the client side. In this case the route could have an alternative JSON response via respond_to.
Alternatively, you could send a message from the background job to the client once processing is finished, via WebSockets or something like message_bus.
You can configure the :host option for the derivation_endpoint plugin:
Shrine.plugin :derivation_endpoint, host: "https://cloudfront.net"
I've tried several things:
just using the url:
resource url: '//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css', disposition: 'head'
local url with linkOverride:
resource url: '/lib/bootstrap/css/bootstrap.min.css', linkOverride: '//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css', disposition: 'head'
using the baseurl mapper config:
grails.resources.mappers.baseurl.modules = [
core: "//netdna.bootstrapcdn.com/"
]
resource url: 'bootstrap/3.0.0/css/bootstrap.min.css', disposition: 'head'
None of these work. I always get some form of
Resource not found:
//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css
Any help is appreciated.
Co-incidentally I am working on it right now as I see the question.
Looks like we have to explicitly use http for the CDN url.
resource url: 'http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css'
Same goes with linkOverride.
Grails 2.1
I've declared the following new resource module to support Google Map API in my views:
'google-map' {
resource url: 'http://maps.googleapis.com/maps/api/js?key=MyGoogleApiKeyGoesHere&sensor=false', attrs: [type: "js"], disposition: 'head'
}
Now when I include this module into some of my pages I get the following HTML code in result:
<script src="http://maps.googleapis.com/maps/api/js" type="text/javascript" ></script>
As you can see the parameters part of URL was removed by some reason which causes an error (Google says that sensor parameter is required when I try to open the page).
Does anybody know how to prevent Grails Resources plug-in from removing query parameters from URLs?
I am using an ajax request which works in local, not in remote, because of an url problem. It looks like :
$.ajax({
type: "POST",
url: "../classes/file_to_process.php",
data: "my data"
success: function(msg){...}
})
I keep on having an error message : "The requested URL /classes/file_to_process.php {without the double dots behind it} was not found on this server"
My working directory is in a folder /prod, in which there is the index.php. The /classes folder is at the same level as /prod. So to fetch it from an jquery request, I use ../classes/file_to_process
I tried an absolute path by using pwd to fetch the correct path on the remote server, but I have the same message
Anybody has an idea ?
'classes' folder is on the same level as 'public', then you can't access it directly from the client (AJAX, JavaScript, etc). You need to either put it in the 'public' or map it to /classes virtual path. Or you can have a trusted .php file in your 'public' folder that accesses the 'classes' on the server side.
TL;DR;
From the client side you cannot access a file that is not being served to the client.