Static file serving in Keystonejs 6 - keystonejs

I am using Keystonejs 6 and some models contain image type fields. When fetching this data I get a src of that image which points to /public/images/myimage.png. This link successfully gets loaded with admin panel logged in (session created) but when I request this src address from a browser anonymously, it redirects my request to the signin page. I can't find setup guide about static serving in Keystone 6. Although in Keystone 5 it seems exist in the documentation, in Keystone 6 nothing I can find in documents or community forum. Does Keystone 6 supports anonymous static file serving (serving public directory) and if it is possible how can I do this?

you can create a folder named public, then under extendExpressApp add the following code
app.use("/public", express.static("public"));
(follow express documentation https://expressjs.com/en/starter/static-files.html)
add this line under ui publicPages: ["public"], to skip admin authentication
now your public folder should be accessible.

Related

DownLoad VichBundle file Api Platform

I'm using API platform with VichBundle to store file on the back side and React Native on the Front side.
I've followed the documentation of API platform and the upload part is working well, but I don't know how to download the document.
When I make a GET request I have the entity with the url of the file but I can't do a GET request with this url because there is no route to this file.
Can somebody give me an exemple of how to download file with api platform and Vichbundle.
Thanks
If you are following Api Platfom's documentation your files should be uploaded to your project's ./app/public/media/ folder and available making an HTTP GET request to http(s)://<yourdomain>/public/media/<filename>.<extension>. Just open the URL in your browser.
To get the exact url query yout API for me mediaObject information (for example, /api/media_objects/{id}) and check the contentUrl property.

ListBucketResult xml trying to show home page of site in S3 thorugh CloudFront

I created a bucket where I´m hosting my static website.
I set the properties to use it as static website hosting (which index document value index.html)
The URL was: http://mywebsitelearningcurve.s3-website-us-east-1.amazonaws.com (not currently up, just to explain)
I exposed it as public (permission).
Overview of my bucket
/images
/static
/asset-manifest.json
/favicon.ico
/index.html
/manifest.json
/service-worker.js
Using http://mywebsitelearningcurve.s3-website-us-east-1.amazonaws.com I could access to my site. However I decided to use CloudFront in front of my bucket.
I created a new distribution for WEB.
On Origin Domain Name I used mywebsitelearningcurve.s3.amazonaws.com
Origin ID: S3-mywebsitelearningcurve
In Viewer Protocol Policy I selected: Redirect HTTP to HTTPS.
Once it finished and I waited for a prudential time to propagate, I had the url https://d2qf2r44tssakh.cloudfront.net/ (not currently up, just to explain).
The issue:
When I tried to use https://d2qf2r44tssakh.cloudfront.net/ it showed me a xml
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Name>mywebsitelearningcurve</Name>
...
...
...
</ListBucketResult>
However, when I tried https://d2qf2r44tssakh.cloudfront.net/index.html it works properly.
I go through several tutos and post but I can´t still make it work. Anyone can provide help?
Thanks
I had the same problem today and was able to fix it by adding index.html to the Default Root Object in the distribution settings:
Optional. The object that you want CloudFront to return (for example,
index.html) when a viewer request points to your root URL
(http://www.example.com) instead of to a specific object in your
distribution (http://www.example.com/index.html).
i had 5 years prod experience on AWS with 5 certifications in place.
When it comes to s3 + cloudfront, i got always in troubles
I tried to automate that using Cloudformation, but Cloudformation does not support everything needed (.i.e. custom origin in cloudfront).
At the end, i relies only on terraform to automate this part:
https://github.com/riboseinc/terraform-aws-s3-cloudfront-website/blob/master/sample-site/main.tf
If you don't mind to use terraform, i highly recommend to jump there.

Protect a directory with regular Laravel Auth

I have a secondary application that drops new folders into my Laravel application on a daily basis. The contents of the folder need to be publicly accessible because they're flash files with a number of assets placed in each day's folder, alongside static .html pages, .jpgs, and .swfs. These links are part of the secondary application's vendor-coded framework.
Moving the files from a non-web accessible folder using php doesn't seem like a good option. I've tried using readfile() and considered .htaccess, but I don't want a secondary login for my users.
Only users who have logins with my Laravel application should have access to these files. Is there some way I can protect access to any request inside this folder with Laravel's Auth system, not basic auth? With the understanding that the page requests inside that folder vary?
From extensive searching, I've found that Laravel cannot handle the protection of public folders with static assets. This is a web server configuration issue.
One solution would be to set a cookie that gets read by the web server and bounces the user if the cookie value does not match a predetermined value. But Laravel encrypts cookies and disposes of cookies not encrypted on each load. So that solution would only work if you use App::filter to process the cookie using php setcookie().

MVC 4: How to add some specific URL directly to BundleConfig

How to bind a virtual url (other than "jquery.js") in a BundleConfig.
example : "www.xyz/xyz.js"
I can't keep one JS file in my local folder, I have to access it directly from web.
I tried this link, but it couldn't help me. Using CDN in MVC script bundle. What am I missing?
Thanks.
Himanshu Pareek.

How can I host multiple websites in IIS 7 and use the same MVC application for all them?

How can I host multiple websites in IIS 7 and use the same MVC application for all them such that each website:
Has it's own root directory so user's can upload their own files (html, css, javascript) without seeing other websites'content
Uses the same MVC application - so updates to the application affect all sites
Users cannot affect the MVC application in any way (preferably it will be hidden from them)
Thanks!
Create a directory where you deploy the MVC files, named "AppFoo". Note that the configuration file web.config will be shared between all of the sites, you'll have to load per-site configuration at on-demand runtime by looking at the Host HTTP header or other binding information.
Create each website in IIS and get it to use the the application directory you created. Ideally each website runs under its own application pool with its own user-account, all of the user-accounts will have access to AppFoo directory.
Create a new directory somewhere, e.g. under C:\Inetpub\sites\ named WebsiteA, WebsiteB, etc. Each folder re-sets the NTFS permission ACLs that only allows each website's application pool user access. Inside these create folders called "Content", "Views" and "Logs"
For each website in IIS (I assume you're using the root) set up a Virtual Directory called "Content" and "Views" (which is how I assume you have set-up your MVC applications), map these to subdirectories of the folders you created in Step 3.
For each website, go to the Logging page and set the log-path to the Logs directory you created for the site in step 3.
Note that this plan is based on the assumption that MVC evaluates IIS virtual directories in its VirtualPathProvider. If not then you'll have to roll your own VirtualPathProvider to load per-website content, again, on a per-hostname basis.
If you are running one code base, then setup one site that uses domain routing or a global filter to capture the domain, save it and use it as a key for folders, etc...
public class DomainFilterAttribute : ActionFilterAttribute
{
private SiteDomainRepository _siteDomainRepository = new SiteDomainRepository();
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var viewBag = filterContext.Controller.ViewBag;
var host = HttpContext.Current.Request.IsLocal ? "www.testdomain.com" : HttpContext.Current.Request.Url.Host;
var domain = hostSplit[1];
var siteDomain = _siteDomainRepository.GetByRowKey(domain);
viewBag.DomainName = host.ToLower();
viewBag.Domain = siteDomain.RowKey;
viewBag.Class = siteDomain.Key;
viewBag.TrackingCode = siteDomain.TrackingCode;
}
}