
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:

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

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

Yes, its adding some headers to the response payload

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

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.”

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

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

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.

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).

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

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>
.

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.)

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

Access-Control-Allow-Origin: *

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'


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

yup

$ 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

Postman shows these headers being returned for the above URL:

individual pkg page is missing the header

which seems odd, since that page is responding with JSON and https://github.com/racket/pkg-index/blob/30d58933d0f26781c36b29262a2a7635e1eec9e7/official/dynamic.rkt#L229

unless that JSON blob is a generated static file

which seems highly probably considering the extension


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

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

OK, I’ll open an issue

done

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

Ya, that’s a never for me.

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)

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

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

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

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
.

Looks like it’s just SO_REUSEADDR
:

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

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:)

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

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.

Ah, thanks for that link.


Looks promising. I could make a socket using the FFI

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.

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

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:

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

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.

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.

Yep.

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?

Or is rktio itself shared between the implementations?

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

drracket but i’d like to use vscode…

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

Thanks @greg

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

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

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

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

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

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:

rktio is shared

Racket CS doesn’t use Chez io

@chris613 have you tried https://github.com/Saigut/intellij-scheme\|https://github.com/Saigut/intellij-scheme

@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

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

quickly, but its just syntax highlighting etc right ?

Seems like it would be pretty straightforward to add a serializer and deserializer for scheme_listener_type
here:
would a similar change need to be made somewhere in the place implementation for CS?

sorry, I haven’t tried it.

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

Thanks!


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

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

Use sync/timeout
instead of channel-get
.


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.

Thanks!

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

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)
.

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