Fork me on GitHub
#clojure
<
2015-08-12
>
onetom03:08:18

is there a built in option in ring to serve a default index.html file? i found this middleware to do exactly what i need: https://github.com/relaynetwork/ring-middleware-index-file but i suspect there should be no extra package necessary for this.

zane03:08:49

@onetom: Can you say a little more about what you're trying to do?

zane03:08:18

What's the most idiomatic way to conditionally require something based on a value?

onetom04:08:58

Just as the linked page explains, I would like to do:

(wrap-index-file “/some/route”)
• Requests to /some/route will redirect to /some/route/.
• Requests to /some/route/ will return the index.html file.

onetom04:08:41

Although I've just found out that my middleware library just started to support this by default recently: https://github.com/pandeiro/boot-http/commit/b310feb852d141248401a27938e87c0f77e7ea8f

Pablo Fernandez09:08:57

I have an empty route table with compojure and it’s still able to server static files from public. Any ideas why?

kardan10:08:46

middleware?

sandbags10:08:59

pupeno: do you have (compojure.route/resources) in there somewhere?

Pablo Fernandez10:08:15

wrap-defaults is what was adding the static management. sandbags I did, but I removed it and I was surprised it kept on working.

sandbags10:08:28

pupeno: ah, yeah

voxdolo16:08:01

I'm hopeful this is a dumb question with an easy answer that I'm just missing: in Ring is there a way to know if the last request was the result of a redirect?

timgilbert16:08:35

Uh, you could check the HTTP status code? 301 or 303 signify redirects

voxdolo16:08:04

timgilbert: sure, but I need to know if the previous request was a redirect, not if the current one is. e.g. "was the user redirected to this URL" not "Is this request a redirect"

voxdolo16:08:40

the best I've been able to come up with is adding a middleware that looks for redirects and assoc's a flag to the session when the request is a redirect and dissoc's it when it's not.

voxdolo16:08:58

and that doesn't work since only the request passes through midddleware and the response is the only thing that indicates that a given request resulted in a redirect

tcrayford16:08:18

@voxdolo: this is an http thing, not a ring thing 😉

voxdolo16:08:34

yeah, but I need to be aware of it inside the ring app

tcrayford16:08:06

I think in general you can't see that a request came from a redirect inside http. I'd vote for looking at the RFC though

voxdolo16:08:08

I'm working at a rate-limitter and I don't want to frequency-based rate-limiting of redirected requests

voxdolo16:08:56

tcrayford: no, you are correct. The "Location" header is handled on the client and is not mentioned in the respondent request

voxdolo16:08:08

thus I'm looking for a workaround… but failing to find one.

tcrayford16:08:01

are you issuing the redirects? or could they be coming from any external app?

voxdolo16:08:19

only the ones I issue are of concern

tcrayford16:08:50

can you just redirect with a query param that you then strip inside a middleware then?

voxdolo16:08:05

I hadn't thought of that simple_smile

voxdolo16:08:08

I could, yes.

tcrayford16:08:21

or throw something into the session on the way out of a middleware

voxdolo16:08:36

that's been my initial tact, but becoming aware of whether the previous request was a redirect was where I got stuck… and the redirect response as provided by ring.util.response doesn't have access to the request

voxdolo16:08:16

I can just stop using ring.util.response/redirect since it doesn't do all that much and require the request is passed in so I can assoc a key to the session when issuing a redirect

tcrayford16:08:35

seems reasonable

voxdolo16:08:19

for some definition of reasonable 😄 That just requires I touch a lot more code than I was hoping to.

voxdolo16:08:51

thanks for helping me think through it though and glad to know I wasn't too far off in my efforts.

voxdolo16:08:15

I don't suppose there's something analogous to ring's middleware that operates on responses, rather than requests?

oliy16:08:01

the middleware is all chained up - the request goes in, the response comes out so if you want to get hold of the response, you can do this

(defn my-middleware [handler]
  (fn [request]
    (let [response (handler request)]
      (assoc response :foo :bar))))

voxdolo16:08:29

oliy: ah! wonderful simple_smile

voxdolo16:08:09

that makes total sense… head-desk-worthy now that you point it out.

tcrayford16:08:40

@voxdolo: oh, I was confused about why you couldn't touch the response in the middleware. @oliy sorted it though simple_smile

timgilbert17:08:20

@voxdolo, kind of hacky and maybe not 100% reliable, but maybe you could check the Refrerrer header and use some heuristics to determine redirects if you are looking for them from a specific source?

voxdolo17:08:46

@timgilbert: I was able to determine if the response was a redirect by calling the handler on the request as oliy suggested

arrdem18:08:34

Is there an Apache project that's a good fit for record storage? I'm (ab)using Lucene with an _id property to emulate an embedded MongoDB and it smells pretty bad.

swizzard18:08:33

why not just use regular mongodb?

arrdem18:08:11

I'm trying to build a tool for tracking my own todo list and notes which must be able to 1) function offline 2) be able to synchronize across machines 3) do full text searching. What I'm currently thinking about is essentially using a Git like FS backed hash named object store (which will synchronize nicely with existing tools) and a parallel solr index for content.

arrdem18:08:37

But I'm not convinced that's the best minimal solution because it means reinventing something that's either Git or Datomic done badly or both.

marcus18:08:42

Hi all, n00b question: how can I compare maps?

marcus18:08:29

I have two maps, and I want to see if they are "equal", meaning they are exactly the same in contents (keys / values).

swizzard18:08:24

(= my-map my-other-map)?

marcus18:08:36

no, always returns 'false'

marcus18:08:03

Ok, I'll review my code.

ghadi18:08:22

both Clojure maps, or is one of them not?

marcus18:08:58

Both are clojure.lang.PersistentArrayMap

ghadi18:08:41

post em if you can. triple-tick to quote code here

ghadi18:08:40

i think you might mean (= targetperm (getpermission exampleperm))

bostonaholic18:08:58

you're calling getpermission on exampleperm but then comparing targetperm with exampleperm

marcus18:08:28

boom, works

marcus18:08:23

Thanks guys!

lvh19:08:51

Is here something like partition-by that partitions when a fn returns a specific value, rather than a different value?

lvh19:08:45

I.e., [1 2 3 4 1 5 6 1 7 8] ;; => [[1 2 3 4] [1 5 6] [1 7 8]]

lvh19:08:07

I guess I could just write the reduction myself, but that seems deceptively close to a partition-by trick...

rauh19:08:06

Sorry, paste mistake simple_smile

emil0r19:08:15

anyone know of common causes for errors like "CompilerException java.lang.IllegalArgumentException: Can't define method not in interfaces" when it's very clearly defined in the interface and used to work?

lvh19:08:01

rauh: cool, thanks!

Lambda/Sierra19:08:48

@emil0r: Incorrect type hints or stale .class files are two possibilities.

emil0r19:08:05

hmm... did a lein clean. that should clean it out right?

Lambda/Sierra19:08:35

@emil0r: if you started a new process after the clean, then yes.

emil0r19:08:48

still got the same error after i tried that

emil0r19:08:14

sigh... think i found it. refactoring ahoy 😞

emil0r19:08:26

thanks though

dottedmag21:08:39

Are there helpers for writing macros? I am trying to write a macro which walks the syntax tree passed to it and basically pattern-matches-replaces some constructs. Walking the tree manually is a bit of work.

mpenet21:08:53

arrdem: isn't it what ElasticSearch is doing

mpenet21:08:08

arrdem: you can probably run it embedded too, but that's maybe too large/heavyweight of a dependency for your use case

sdegutis21:08:26

Hello. I have been hinted to join this chat room to ask Datomic question. Please advice?

mpenet21:08:12

sdegutis: probably better at #C03RZMDSH

Alex Miller (Clojure team)21:08:06

you're showing (getpermission exampleperm) but comparing exampleperm ? should that be (= targetperm (getpermission exampleperm)) ?

Alex Miller (Clojure team)21:08:23

sorry, lagging client - ignore! :)

arrdem21:08:26

mpenet: quite possibly I haven't tried to evaluate it yet

rauh21:08:30

@arrdem: I've embedded an ES server before. If you need some code... it also runs fine with like 200MB RAM. Nothing too crazy

arrdem21:08:27

@rauh: so after some research it looks like the document IDing thing I was condemning earlier is a very common ES/Lucene practice so since it's working I'm just gonna stick with it for simplicity's sake.