How to handle 404 in cowboy_static when file not found - erlang

I have very important query regarding cowboy_static
{"/api/assets/[...]",cowboy_static, {dir,"/home/upload_dir/"}},
{"/api/assets/[...]",cowboy_static, {dir,"/home/upload_dir/"}},
Everything is working fine but I failed to send a default image (for example not_available.jpg) for 404 .
Is it possible in cowboy_static to send a default image if request image/URL not found.
Thanks in advance.

I do not think there is a way of doing it with just cowboy_static handler. The documentation (static files) says
Cowboy comes with a ready to use handler for serving static files. It
is provided as a convenience for serving files during development.
For systems in production, consider using one of the many Content Distribution Network > (CDN) available on the market, as they are the best solution for serving files.
so some functionality may be missing there. If you really want to serve 404 custom page from Cowboy, I think the only option is a custom handler instead of cowboy_static.

Related

Need Docker configuration on Render.com to serve static files

Currently the way Docker is set is that Django serves static files i.e. style-sheets etc which takes care of the design of my web app.
When I turn DEBUG Mode off, Django lets the actual server serve static files, for performance --- but currently docker (hosted on Render.com) is not configured to do that --- therefore the website is haywired and the design is all wacked out.
Sorry, I'm a noob. Any advice would be appreciated.
The WhiteNoise library can help you with this! Check out the WhiteNoise docs or https://render.com/docs/deploy-django#static-files.
On Render, the internet-facing web server is provided by default and we need a way to host static files using it. In this step, we will set up WhiteNoise which is a highly popular solution for this problem. The following instructions are a short overview of the procedure described in the WhiteNoise documentation.
The WhiteNosie docs or Render's Django Deploy docs will walk you through the process of configuring WhiteNoise to serve your static assets.
This architecture works for most sites, but if you have a very high-traffic site, you might want to explore the django-stores library, which you can use to upload static assets at build-time to something like S3 so that they are served from there and allow your Django app to focus on only serving dynamic (non-static) requests.

What are the options for swagger-editor to save json or yaml into remote backend?

I know that the Swagger-editor saves api documentation into the local browser cache ("Download Yaml/Json" and "Export Yaml/Json").
But what if I want to save it into a remote server then latter I can continue editing it from another browser.
Are there already known Backends for Swagger-editor which I can use?
Thanks in advance.
The swagger-node project has the editor built in and saves files in your filesystem.
Follow the steps in the README to install and run. When you make changes in the editor that you launch (your browser), they are autosaved, and you can see the change in the api directory. For example, if you change the { info: { title } } key, you'll see it autosave and then you can see the change in ./api/swagger/swagger.yaml.
There is an option to useBackendForStorage: true which does a HTTP put to a backend server.
Little late to the game, but maybe helps others:
There is a very simple backend here, written in go:
https://github.com/zgiber/sweb
It runs as a http server on your localhost, and opens the editor in a browser. Saves the swagger file as you type.

How do I handle post requests from my dart app ran from the dart editor?

I have code that looks something like this (_http is the angular Http object)
var httpFuture = _http.post('/api/items', {
'ids': JSON.encode(new List.from(nonLoadedIds))
});
httpFuture.catchError((e) {
Logger.root.severe('Unable to load items!', e);
});
It is making a post request to load a bunch of things. Potentially more ids than the http get header can handle.
The nice development experience would be if I could fire up the dart editor, mock up some fake response data, run my app, and see the data in the end. I would also accept being able to start up a separate web app and somehow proxy my post requests to that web app.
What I don't want to do is change my '/api/items' into something like 'http://localhost:8084/api/items' mostly because I don't want to have to remember to replace these before deploying (I know I'll forget) and while doable, I don't want to on my server implement CORS just to have to remember to disable it when I deploy to production.
But really, I would accept just about any workflow if it is recommended. I just would like to eliminate any manual code transformations pre production deploy.
The suggested attempt is to use a simple proxy server which forwards to pub serve.
See for example https://code.google.com/p/dart/issues/detail?id=18039
This issue contains the source code for a simple custom proxy server example https://code.google.com/p/dart/issues/detail?id=15731
see also
Dart: How to use different settings in debug and production mode?
How to achieve precompiler directive like functionality
Is there a compiler preprocessor in Dart?

Why am I getting the message "The specified request cannot be executed from current Application Pool"?

Quite not sure why I see this error.
I navigate to my Login View like so http://test.staging.com/mywebsite/Login
My Login view was just redone using MVC but I have seen this same error message going to an aspx page as well...
If I use http I get the error message The specified request cannot be executed from current Application Pool.
If I use https://test.staging.com/mywebsite/Login, I'm good.
If I don't specify a protocol, test.staging.com/mywebsite/Login, I get the error as well
Is there an error happening under the covers and my custom error page can't be shown like discussed here?
What are some other causes of this error?
That usually means your custom errors are configured to run as a different AppPool.
You can read more at MSDN. (See section "Using Custom Errors from Another Application Pool").
There are two ways to correct this behavior. The first is possibly not one that you are interested in because it would require you to change your current architecture and run both sites in the same application pool (such as share the same worker process memory space). To do this, simply move the /errors virtual directory to run in the same application pool as the site for which it serves the custom error.
The second way is to make use of a registry key provided by IIS 6.0. This registry key makes sure IIS 6.0 does not check the metadata during the execution of the custom error and therefore allowing this to work.
See the article for information on the registry key fix.
It may also mean that you are using something along the lines of Server.Transfer to a page that is in a different AppPool.
It could be because you're using different versions of ASP.NET for one or many apps in the pool.
Make sure all apps in the pool use the same version of ASP (e.g. ASP 2.0.50727)
If you just added a new app, try changing the app momentarily to a different version of ASP, then back to same version. I experienced an issue where the displayed version was correct, but under the hood, a different version was used!
Check your event log, under Application, to get more details about the error.
The message would be caused by your page server-side redirecting to a page served by another application pool. Such as for example, in your link, the error page.
I know this is an old thread, but I stumbled upon it and found a different solution. Here's what worked for me: Make sure your application handles .asmx files correctly
From IIS:
Right Click on your project > Properties > Configuration
If necessary, add the .asmx file extension that maps to the aspnet_isapi.dll
Limit to: "GET,HEAD,POST,DEBUG" and restart.
Because I can't comment on vcsjones's answer, I'll add it down here. The DWORD value IgnoreAppPoolForCustomErrors needs to be set under HKLM\SYSTEM\CurrentControlSet\Services\W3SVC\ Parameters vs HKLM\SYSTEM\CurrentControlSet\Services\W3SVC referenced in that technet article. Set it to 1 and do an iisreset and you're good to go.
Source Blog Post
In my particular case, I received this error while trying to serve a content (non ASP.NET) website while it was an Application. Right-Clicking the virtual folder and removing the application fixed it for me.
In my case the application used the application pool that didn't exist. I have no idea how it's happened.

PHP extension loading from script using dl()

I'm going to buy a (cheap) hosting space with apache/php 5/mysql. Because it's cheap i have no direct control over php.ini and extension loading.
My question is: can i load an extension putting the .dll file into my space and than using dl() php function? Can the host disable this feature thus avoid loading custom extension this way?
Yes, it can be disabled through the enable_dl and safe_mode php.ini settings (which would almost certainly be the case, as otherwise you could e.g. load your own code in the web server process).
And that's in addition to the disable_functions setting, which can disable anything.
the host can disable any function within php from the php.ini. in fact I would be surprised if the host left this feature on.
Since you're talking about a .dll, you are assuming to get a Windows hosting server running PHP, however, is better that you check with the hosting company, because probably dl() will be disabled.
Smaller hosting companies can be more accommodating with adding extensions you may require.

Resources