Yaws code inside <erl></erl> not running - erlang

I am trying out Yaws, however I have run into a bump. The code inside my .yaws file is not compiling when I got to the path, instead it is being printed on the window. Here is my code and configuration:
<erl>
method(Arg) ->
Rec = Arg#arg.req,
Rec#http_request.method.
out(Arg) ->
{ehtml, f("Method: ~s", [method(Arg)])}.
</erl>
Server configuration:
<server localhost>
port = 8000
listen = 127.0.0.1
docroot = /home/something/
dir_listings = true
dav = true
auth_log = true
statistics = true
</server>
Any info would really be appreciated, thank you.

The problem is that you have dav = true in your server configuration, which turns on WebDAV, a protocol for content management. Under this configuration, a .yaws file is treated as just a regular file, not as one that requires special Yaws processing, which is why you see the verbatim contents of the file when you access it via your browser.
Removing dav = true from your configuration and then restarting Yaws will make it process your example.yaws file as you expect.

Related

Vaadin 23 behind Traefik reverse proxy

I'm looking for an example of Traefik toml config file to serve a newly created Vaadin app. My current config is :
[http]
# Add the router
[http.routers]
[http.routers.esus]
rule = "Host(`app.acme.com`)"
service = "esus"
entrypoints = ["web","websecure"]
passHostHeader = true
[http.routers.esus.tls]
certResolver = "letsencrypt"
# Add the service
[http.services]
[http.services.esus.loadbalancer]
[[http.services.esus.loadbalancer.servers]]
url = "http://srvdock01:8086"
With that, I've got a blank screen. I suppose that it is due to header forward configuration or maybe websocket.
Some help would be really appreciated.
Regards,
Alex

How to get uwsgi to work with internal routing

Hi I'm trying to to get uwsgi to serve static files and untimately to try adding ".js" if the file was not found before defaulting to the python app.
I already compiled the pcre support into my uwsgi but still cannot get it to work.
As a first step I tried to set up a simple example. I created a file settings.ini:
[uwsgi]
route = ^/hi rewrite:/hello.html
route = ^/logo static:/icon.svg
route = ^/huhu static:/hello.html
and run
uwsgi --ini settings.ini --http=127.0.0.1:8000 --check-static static --wsgi-file app.py
The content of app.py is not relevant but I post it for completeness:
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"went to python app"]
If I put files in a subfolder static (e.g. static/hello.html) then they are served correctly, also app.py is called when I navigate to anything that is neither found in the static folder nor matches anything in settings.ini.
However, if I navigate to http://127.0.0.1:8000/hi it goes to the app. I would expect to be served hello.html.
And if I navigate to http://127.0.0.1:8000/huhu I get The connection was reset error on the browser.
I also tried adding plugins = router_static or plugins = router_rewrite to settings.ini with no success.

Lua resty_dogstatsd only publishes first instance

I have a metric client that looks something like:
package.path = package.path .. ';../?.lua'
local metrics = {}
local resty_dogstatsd = require('resty_dogstatsd')
local logger = require('module.utils.logger')
local _statsd = resty_dogstatsd.new({
statsd = {
host = config.dataDog.host,
port = config.dataDog.port,
namespace = config.dataDog.namespace
},
tags = config.dataDog.tags
})
function metrics.incMetric1 ()
logger.debug('Updating metric metric1');
_statsd:increment(metric1 1, 1)
end
return metrics;
Then in my application I import it and use it
local metrics = require('module.metrics')
-- somewhere, some condition
metrics.incMetric1()
This publishes the log Updating metric metric1 in datadog and I can see it. But this will only publish the first instance. Until I restart service nginx restart, I will not get any more increments.
Update
So I have a start.lua in /etc/nginx/conf.d/start.lua that is:
package.path = package.path .. ';/path/to/my/app/?.lua'
local app = require('app.init');
app.start()
And the nginx config is
rewrite_by_lua_file /etc/nginx/conf.d/start.lua;
If I were to copy/paste the metric code into start.lua, then the metric is updated every time. Why is this?!
Update
I noticed this in the error logs:
2018/05/23 10:02:07 [error] 24483#0: *6 attempt to send data on a closed socket: u:some-hex, c:some-hex, client: 123.12.0.123, server: *.my-url.com, request: "GET / HTTP/1.1", host: "my.my-url.com"
This happens on the 2nd request to the nginx; the first time after restart, this is all fine ...
Update 2
This happens only if I have a metrics file and require it in my other. So if I instantiate the resty_dogstatsd client inside the main lua file, then everything is fine ...

HHVM+Hacklang: errors/warnings output into browser

Is there any way to tell HHVM to output Hacklang warnings and errors into the browser? Something like PHP does with enabled display_errors, display_startup_errors and error_reporting set to E_ALL
HHVM version:
$ php -v
HipHop VM 3.1.0-dev+2014.04.09 (rel)
Compiler: heads/master-0-g4fc811c64c23a3686f66a2bea80ba47f3eaf9f3d
Repo schema: 79197c935790c0b9c9cb13566c3e727ace368117
I've tried the following config:
$ cat /etc/hhvm/php.ini
; php options
display_startup_errors = On
error_reporting = E_ALL
display_errors = On
; hhvm specific
hhvm.log.level = Warning
hhvm.log.always_log_unhandled_exceptions = true
hhvm.log.runtime_error_reporting_level = 8191
hhvm.mysql.typed_results = false
And :
$ cat /etc/hhvm/server.ini
; php options
pid = /var/run/hhvm/pid
; hhvm specific
hhvm.server.port = 9000
hhvm.server.type = fastcgi
hhvm.server.default_document = index.php
hhvm.log.level = Warning
hhvm.log.always_log_unhandled_exceptions = true
hhvm.log.runtime_error_reporting_level = 8191
hhvm.log.use_log_file = true
hhvm.log.file = /var/log/hhvm/error.log
hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc
hhvm.mysql.typed_results = false
hhvm.debug.full_backtrace = true
hhvm.debug.server_stack_trace = true
hhvm.debug.server_error_message = true
hhvm.debug.translate_source = true
tl;dr: You can't.
The thing to keep in mind here is that the typechecker does a static analysis of your code while the PHP errors you talk about show up at runtime. If this was C++, you could compare the Hack typechecker errors with the errors during the compile step - so Hack tells you things that are wrong before the code even runs.
The trick is to use either the vim or emacs plugins which warn you of errors as you save the file, or use hh_client from the terminal, or build a plugin for your favorite IDE (feel free to send pull requests!). hh_client --json gives an easy to parse output if you want to build a plugin for Sublime Text, or Eclipse or whatever you want.
Note that some errors are runtime errors, while some aren't. Function args as well as return types should throw exceptions at runtime for the latest HHVM build for example. The problem there is that you only see those errors when you hit a certain code-path. The beauty of Hack is that it errors for all the problems in your code, even if it's a code-path you may not test at runtime.

uWSGI as a standalone http server with lua

I'm trying to set up uWSGI to run as a standalone server running a simple LUA script(right now, as a POC, using the hello world from http://uwsgi-docs.readthedocs.org/en/latest/Lua.html).
Here's my uwsgi.ini file:
[uwsgi]
master = true
workers = 1
threads = 8
listen = 4096
max-request = 512
pidfile = /uwsgi/logs/uwsgi.pid
procname-master = uWSGI master
auto-procname = true
lua = /uwsgi/hello.lua
socket-timeout = 30
socket = /uwsgi/uwsgi_1.sock
http = 127.0.0.1:80
http-to = /uwsgi/uwsgi_1.sock
When sending a web request, an empty response is received, and uWSGI process outputs:
-- unavailable modifier requested: 0 --
I've read this usually means a plugin is missing, however, LUA plugin is installed, and when doing the same but through NGINX everything works fine, which means there's no problem loading LUA.
Any help please?
Thanks.
Somebody told me I had to add http-modifier1 = 6 and now it works.
Still don't understand what does '6' mean, but whatever.

Resources