massung
2020-2-23 16:03:46

Is there any chance that https://pkgd.racket-lang.org could add CORS support? Right now it blocks requests from other pages, and so - for example - from my homepage I can’t lookup current version and build status of my package(s) to present them to users. :wink:


spdegabrielle
2020-2-23 16:20:01

Not my area of expertise but I’m sure if you took a go at implementing this the PR would be appreciated. https://github.com/racket/pkg-index\|https://github.com/racket/pkg-index


spdegabrielle
2020-2-23 16:25:40

I’m guessing a CORS implementation would be an extension of the web server ? (I only just looked at the CORS Wikipedia page so I’m only guessing.) https://github.com/racket/web-server\|https://github.com/racket/web-server


d_run
2020-2-23 16:26:11

Yes, its adding some headers to the response payload


d_run
2020-2-23 16:27:01

Koyo does it with a middleware - https://github.com/Bogdanp/koyo/blob/master/koyo-lib/koyo/cors.rkt but it can be pretty simple


philip.mcgrath
2020-2-23 16:27:50

But no change is needed to the web-server library: you just have to add the right headers. More to the point, you have to come up with a definition of “right.”


spdegabrielle
2020-2-23 16:31:26

Thanks @philip.mcgrath & @d_run I’m hoping this helps @massung


massung
2020-2-23 16:32:54

The server needs to add this to all responses: Access-Control-Allow-Origin: *


massung
2020-2-23 16:33:54

Then it’ll just work.

CORS is something implemented at the client-level in browsers. It’s basically just a way to prevent one site from snagging data from another site and presenting it as its own.


massung
2020-2-23 16:35:30

In the server code, if you wanted to limit what is allowed to be cross-origin, then you’d conditionally add the header to the response based on the request (e.g. maybe only end-points that return JSON can be cross-origin).


massung
2020-2-23 16:37:41

You may - optionally - only want to support GET requests with CORS: Access-Control-Allow-Methods: GET


philip.mcgrath
2020-2-23 16:43:36

But is <http://pkgd.racket-lang.org\|pkgd.racket-lang.org> actually what you want? The actually package catalog (and all of the static content) is at <http://pkgs.racket-lang.org\|pkgs.racket-lang.org>.


philip.mcgrath
2020-2-23 16:44:19

Also, I see there already CORS things in some part of the package server: https://github.com/racket/pkg-index/blob/30d58933d0f26781c36b29262a2a7635e1eec9e7/official/dynamic.rkt#L224 (But I’m not deeply familiar with this code.)


d_run
2020-2-23 16:47:14

looking at an XHR and you’re right - they’re there

HTTP/1.1 200 Okay Date: Sun, 23 Feb 2020 16:46:29 GMT Server: Racket Last-Modified: Sun, 23 Feb 2020 16:46:29 GMT Content-Type: application/json Access-Control-Allow-Origin: * Via: 1.1 <http://pkgd.racket-lang.org\|pkgd.racket-lang.org> (Apache/2.4.7) Keep-Alive: timeout=5, max=98 Connection: Keep-Alive Transfer-Encoding: chunked


d_run
2020-2-23 16:47:25

Access-Control-Allow-Origin: *


d_run
2020-2-23 16:52:27

curl -i '<https://pkgd.racket-lang.org/pkgn/json/search-completions>' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:72.0) Gecko/20100101 Firefox/72.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'X-Requested-With: XMLHttpRequest' -H 'DNT: 1' -H 'Connection: keep-alive'


massung
2020-2-23 16:53:00

massung
2020-2-23 16:53:20

My guess is the header isn’t coming through for specific packages.


d_run
2020-2-23 16:53:54

yup


d_run
2020-2-23 16:53:58

$ curl -i '<https://pkgd.racket-lang.org/pkgn/pkg/r-cade.json>' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:72.0) Gecko/20100101 Firefox/72.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'X-Requested-With: XMLHttpRequest' -H 'DNT: 1' -H 'Connection: keep-alive' HTTP/1.1 200 OK Date: Sun, 23 Feb 2020 16:53:46 GMT Server: Racket Last-Modified: Sun, 23 Feb 2020 16:41:28 GMT Content-Type: application/json Accept-Ranges: bytes Content-Length: 1826 Via: 1.1 <http://pkgd.racket-lang.org\|pkgd.racket-lang.org> (Apache/2.4.7) Keep-Alive: timeout=5, max=100 Connection: Keep-Alive


massung
2020-2-23 16:54:01

Postman shows these headers being returned for the above URL:


d_run
2020-2-23 16:54:24

individual pkg page is missing the header


d_run
2020-2-23 16:58:54

d_run
2020-2-23 17:01:44

unless that JSON blob is a generated static file


d_run
2020-2-23 17:02:42

which seems highly probably considering the extension



d_run
2020-2-23 17:06:53

might help to open an issue on the repo specifying that static .json files served from the cache are missing the cors header


d_run
2020-2-23 17:07:12

not sure if thats something that needs to be set in Apache, S3 or Racket


massung
2020-2-23 17:08:12

OK, I’ll open an issue


massung
2020-2-23 17:09:46

done


d_run
2020-2-23 17:10:07

can’t remember the last time i configured Apache, was probably 2012


massung
2020-2-23 17:10:57

Ya, that’s a never for me.


spdegabrielle
2020-2-23 19:14:41

Quick survey; how do you edit Racket code? • :blue_heart: DrRacket • :green_heart: Emacs racket-mode • :yellow_heart: Visual Studio Code • :orange_heart: Vim • :purple_heart: text editor (notepad++, sublime text) • :black_heart: Visual Studio/Xcode/InteliJ/Eclipse • :basketball: Other ? (click below to ‘vote’, please use thread to indicate ‘other’ or make comments)


massung
2020-2-23 19:23:41

I use DrRacket mostly, but Emacs if I hit a weird issue that kills DrRacket (e.g. FFI)


samdphillips
2020-2-23 19:28:27

I was just thinking about a survey like this the other day.


notjack
2020-2-23 19:49:34

CORS sometimes involves a preflight OPTIONS request, is that handled?


popa.bogdanp
2020-2-23 19:56:45

Is the reuse? argument to tcp-listen different from SO_REUSEADDR \| SO_REUSEPORT ? Trying to bind multiple web-server instances (running in different places) to the same address/port fails with system error: Address already in use; errno=48.



popa.bogdanp
2020-2-23 19:58:43

Is there any way to set SO_REUSEPORT on a socket from Racket?


greg
2020-2-23 20:00:08

Tiny note, FWIW: Lately I’ve been calling the whole package “Racket Mode”, because racket-mode is just one of the major and minor modes it provides.

(Probably should have picked some creative name like “Geiser” or “CIDER”. But originally had no idea it would turn into such a big/long project. :man-shrugging:)


greg
2020-2-23 20:01:14

But it’s “racket-mode” on MELPA so that’s… not wrong. :simple_smile:


greg
2020-2-23 20:06:45

Maybe you could use https://download.racket-lang.org/releases/7.6/doc/foreign/Ports.html#(def._((lib._ffi%2Funsafe%2Fport..rkt)._unsafe-port-~3efile-descriptor)) to set it for an existing port… but tcp-listen doesn’t return a port.


popa.bogdanp
2020-2-23 20:08:35

Ah, thanks for that link.



popa.bogdanp
2020-2-23 20:08:44

Looks promising. I could make a socket using the FFI


greg
2020-2-23 20:08:58

I did a PR to add support for SO_RECVBUF for UDP — https://download.racket-lang.org/releases/7.6/doc/reference/udp.html#(def._((lib._racket%2Fudp..rkt)._udp-set-receive-buffer-size!)) — and it wasn’t too hard despite my ignorance. Matthew helped! Maybe you could try similar, for this.


greg
2020-2-23 20:09:29

(This was within the last year, with that new rktio system.)


greg
2020-2-23 20:10:41

I mean, it could be, part one do the hack for now if that works, and part two add it to Racket “properly”. :slightly_smiling_face:


popa.bogdanp
2020-2-23 20:12:08

I don’t really need it for anything practical. I was just updating the Techempower benchmark for Racket to perform less badly and I noticed all the other frameworks take advantage of multiple cores.

I’d been planning on adding sendfile support to Racket for a while so I might just do them both as soon as I get a chance :smile:

https://github.com/TechEmpower/FrameworkBenchmarks/pull/5507


greg
2020-2-23 20:12:26

Or, to back up, it might make sense to say “well one place is the front end and only it directly accepts connections, and it relays them to other places using whatever protocol”. That has its own pros and cons, idk.


popa.bogdanp
2020-2-23 20:13:04

Yeah, if this were for a practical project, I think I’d just run each place on a different port and have nginx reverse proxy between them.


greg
2020-2-23 20:13:10

Yep.


popa.bogdanp
2020-2-23 20:15:26

I haven’t looked very deeply at rktio, but does any change to rktio need to be done twice: in one place for CS and in another for BC?


popa.bogdanp
2020-2-23 20:16:03

Or is rktio itself shared between the implementations?


chris613
2020-2-23 21:10:46

I wonder if results of “what do you wish you could / want to use” would match


jestarray
2020-2-23 21:14:44

drracket but i’d like to use vscode…


jestarray
2020-2-23 21:15:01

i wouldnt mine drracket if it didn’t lag when i type… despite having a beefy pc


spdegabrielle
2020-2-23 21:37:03

Thanks @greg


spdegabrielle
2020-2-23 21:39:02

whoever voted ‘text editor (notepad++, sublime text)’ and ‘Visual Studio/Xcode/InteliJ/Eclipse’ - please say which one and why? :eyes:


spdegabrielle
2020-2-23 21:41:13

…and is there a ‘racket mode’ for the text editor/ide of your choice?


chris613
2020-2-23 21:42:22

i didnt b/c im trying to use emacs as IJ does not support racket out the box and i havent found a decent enough community plugin


chris613
2020-2-23 21:43:28

but in my day-to-day i use IJ for multi language-ish, and im very comfortable there now, switching to a new editor has been a reasonably large hurdle for getting into racket


chris613
2020-2-23 21:43:54

i started of using DrRacket b/c i just couldnt get used to “the emacs way” sort of thing, and over the last few weeks/months ive been getting more comfy with emacs


chris613
2020-2-23 21:44:55

if there was something like https://cursive-ide.com for IJ that could handle racket … id most probably be using that and more than likely would spend a few ££ on it :slightly_smiling_face:


samth
2020-2-23 21:52:38

rktio is shared


samth
2020-2-23 21:52:53

Racket CS doesn’t use Chez io


spdegabrielle
2020-2-23 22:15:07

philip.mcgrath
2020-2-23 22:18:42

@popa.bogdanp There was a mailing list thread that touched on this a while ago, and @mflatt suggested that “it would be portable and straightforward to implement” to allow TCP listeners to be sent across place channels, rather than exposing SO_REUSEPORT: https://groups.google.com/d/msg/racket-users/dwK14kdG4R4/4bLImleUAgAJ


popa.bogdanp
2020-2-23 22:22:19

Thanks, @philip.mcgrath! Looks like I even participated in that thread, but completely forgot about it :sweat_smile:


chris613
2020-2-23 22:27:16

quickly, but its just syntax highlighting etc right ?


popa.bogdanp
2020-2-23 22:52:19

Seems like it would be pretty straightforward to add a serializer and deserializer for scheme_listener_type here:

https://github.com/racket/racket/blob/b63e9a4983a7eb21f9a55e5b33eb2d5a8fef6abc/racket/src/racket/src/place.c#L1152

would a similar change need to be made somewhere in the place implementation for CS?


spdegabrielle
2020-2-23 22:56:43

sorry, I haven’t tried it.


samth
2020-2-23 23:01:53

Yes. I think places are implemented in Racket code in src/thread but that might be wrong



popa.bogdanp
2020-2-23 23:08:46

Thanks!


philip.mcgrath
2020-2-23 23:26:46

capfredf
2020-2-24 00:19:54

What’s the best way to try getting a message from a channel by channel-get but with a timeout?


capfredf
2020-2-24 00:21:02

Right now, I am using a combination of channel-try-get with sleep


mflatt
2020-2-24 01:05:59

Use sync/timeout instead of channel-get.



rokitna
2020-2-24 01:45:17

I picked “text editor.” I use Kate and occasionally Notepad++. Two reasons I’ve bounced off of DrRacket in the last few years are some crashing issues and a kind of unresponsive feel when I type and scroll, but these factors might have gotten better by now. More generally, I tend to be in the habit of using simpler editors because in most languages, I find autocompletion and auto-formatting often interfere with my code rather than helping me out.


capfredf
2020-2-24 02:33:08

Thanks!


capfredf
2020-2-24 03:33:28

if I run my program file like racket -l xxxx -t &lt;myprog_&gt;_, how can i get the file name, i.e. &lt;myprog&gt; at run-time? find-system-path only returns racket in this case.


philip.mcgrath
2020-2-24 04:15:02

That is not the usual way of running a program. If you run your program as racket tmp.rkt, (find-system-path 'run-file) will be a path to tmp.rkt and (find-system-path 'exec-file) will return a path to racket. Also, you can use the --name/-N command-line flag to explicitly specify what path should be used for (find-system-path 'run-file).


notjack
2020-2-24 05:14:38

Related question: is (sync/timeout 1000 e) equivalent to (sync e (alarm-evt 1000))? I’ve been assuming it is.