Decimal 0.5.1+ changed to banker's rounding (round to nearest even
number), and math-functions 0.3.3.0 (used by roi) fixed various
precision-related issues. Now we require the latest versions of these.
This was causing some functional test failures when building with old
GHCs/snapshots.
This commit introduces IPv6 support (and thus closes#1145).
It also allows using local hostnames as a parameter for --host.
For this, multiple things needed to be changed:
- checkWebOpts is dropped, as the supplied parameter is checked later
by Network.Socket.getAddrInfo
- defbaseurl needs to check if : is used in the host, as this indicates
the usage of an IPv6 address. In this case, the host needs to be
wrapped in [] for the base URL
- To allow opening such a modified base URL, runHostPortFullUrl is used
instead of runhostPortUrl, as it allows opening arbitrary URLs instead
of a path prefixed with http://127.0.0.1
As checking the host for validity is postponed until the webserver tries
to start, an invalid hostname leads to an exception caused by
Network.Socket.getAddrInfo.
This is still fine, as hledger-web won't start in an undefined state, but
will terminate with a nonzero exit code.
This commit adds the --socket option to use hledger-web over an AF_UNIX socket
file.
It allows running multiple instances of hledger-web on the same system without
having to manually choose a port for each instance, which is helpful for running
individual instances for multiple users. In this scenario, the socket path is
predictable, as it can be derived from the username.
It also introduces the following dependencies:
- network
- Used to create the unix domain socket
- unix-compat
- Used to identify if the socket file is still a socket, to reduce the risk
of deleting a file when cleaning up the socket
- Modified the cors option to require a String
- Moved the logic to build the cors policy to WebOptions.hs
- Specify the --cors "*" example in the cors option help
- Added utf8-string dependency to convert a String into a ByteString
in JournalReader.hs. If you still need this, feel free to work on
those errors. But hopefully not, because dropping base 4.8 should
permit some code cleanups.
A single transaction can be added by PUT to /add.
(I read that PUT, not POST, should be used to create;
perhaps the web add form should also use PUT ?)
As with the web form, the `add` capability is required (and enabled by
default).
Here's how to test with curl:
$ curl -s http://127.0.0.1:5000/add -X PUT -H 'Content-Type: application/json' --data-binary @in.json; echo
New readJsonFile/writeJsonFile helpers in Hledger.Web.Json
are handy for generating test data. Eg:
>>> writeJsonFile "in.json" (head $ jtxns samplejournal)
base-compat-batteries provides the same API across more ghc versions
than base-compat does, at the cost of more dependencies. Eg it exports
Prelude.Compat ((<>)) with ghc 7.10/base 4.8, which we expect.
My belief is that several of our deps already require it so the added
cost is not too great. We should probably go back to base-compat when
possible though, eg when we stop supporting ghc 7.10.
We don't need to import Data.Monoid because Prelude.Compat exports "<>"
already. In fact, importing that module causes build failures:
Hledger/Read/Common.hs:725:62: error:
Ambiguous occurrence ‘<>’
It could refer to either ‘Sem.<>’,
imported from ‘Prelude.Compat’ at Hledger/Read/Common.hs:97:1-39
(and originally defined in ‘Data.Semigroup’)
or ‘Data.Monoid.<>’,
imported from ‘Data.Monoid’ at Hledger/Read/Common.hs:110:1-18
Fixes https://github.com/simonmichael/hledger/issues/794.
This also validates transaction date and description upon form submission. As noted in
the issue, this removes hledger-web's "smart date" functionality. This
functionality can be restored giving the demand but should be tracked in
another issue.
Previous iterations used input[type=date], but it isn't easily
crossbrowser and the polyfill I found had some quirks.