Hey, first of all I want to say typesense is amazi...
# community-help
r
Hey, first of all I want to say typesense is amazing and I just started using it. It really help me to build reliable search engine in no time. Anyway, looking for any guides what could go wrong. I have created docker version of the typesense with version 0.22.1 which works fine for now, but I am planning to upgrade image soon. however, when I created this version I intentionally
enable cors
to allow me to control collection and document imports from my app, however, creating, or updating works fine nothing looks odd to me, but when I am trying to delete just a collection it doesnt allow me to do it. I tried to find a solution to it but it doesnt look like it exists in documentation as common issue, so decided to try slack community to see if anyone know what might I am doing wrong with it. I have regular call like
() => client.collections("watch_march_17").delete()
but I am getting cors issue:
Access to XMLHttpRequest at '<http://localhost:8108/collections/watch_march_17?x-typesense-api-key=qp23Vu35PtddRVDC6sgCFN9SP7BPc5Z3Fh>' from origin '<http://localhost:3000>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
I also tried
typesense-dashboard
a small project that helps to play with collections, which actually works fine and I can delete collections, but I dont want to use it with production due to couple security reasons, anyway thanks again for further help
j
@Roman Kovtun Could you share the full command you're using to start Typesense?
r
@Jason Bosco
Copy code
docker run -p 8108:8108 -v/tmp/typesense-data:/data typesense/typesense:0.22.1 \
  --data-dir /data --api-key=qp23Vu35PtddRVDC6sgCFN9SP7BPc5Z3Fh9gMuBy --enable-cors
j
That looks fine... Are you calling
() => client.collections("watch_march_17").delete()
from the browser?
r
Yep, regular client call
Copy code
const SERVER_CONFIG = {
  nodes: [{
    host: process.env.typesenseHost,
    port: process.env.typesensePort,
    protocol: process.env.typesenseProtocol,
  }],
  apiKey: process.env.typesenseSearchApiKey,
  numRetries: 8,
  connectionTimeoutSeconds: 2,
}

export const TSAdapter = new TypesenseInstantsearchAdapter({
  server: SERVER_CONFIG,
  additionalSearchParameters: {
    queryBy: 'brand,model,reference',
    queryByWeights: '4,2,1',
    numTypos: 1,
    typoTokensThreshold: 1,
  },
});

export default new Typesense.Client(Object.assign(
  SERVER_CONFIG,
  {
    apiKey: process.env.typesenseAdminApiKey,
  }
));
which does it job creating multiple collections and so, but not delete for some reason, I am actually updating image right, might be the version issue but I am not sure
j
Could you try this on
0.23.0.rc47
?
On a side note, any particular reason you're doing writes to collections from the browser? Because then anyone can extract the API key from the network calls and then be able to write data directly to Typesense outside your application
r
Collections are controlled locally, and I am not going to push the keys to production, that why my original idea was manutally upgrade collection fields on local machine via ssh, but then I decided to build simple UI for my self to play around with it.
👍 1
yeah, just tried this new release and looks like something on my end or so, cuz cannot delete it yet
j
Could you look at the network requests in the browser made for the delete API call, and post the request and response headers?
r
message has been deleted
regular get and second is delete because crash on cors
also the second thing which is really odd is that api response is coming with Network Error, still usual for cors
j
Could you post the output of this:
Copy code
curl -sv -H "X-TYPESENSE-API-KEY: qp23Vu35PtddRVDC6sgCFN9SP7BPc5Z3Fh9gMuBy" \
     -X DELETE \
    "<http://localhost:8108/collections/watch_march_17>"
r
Copy code
>      -X DELETE \
>     "<http://localhost:8108/collections/watch_march_17>"
*   Trying ::1:8108...
* Connected to localhost (::1) port 8108 (#0)
> DELETE /collections/watch_march_17 HTTP/1.1
> Host: localhost:8108
> User-Agent: curl/7.77.0
> Accept: */*
> X-TYPESENSE-API-KEY: qp23Vu35PtddRVDC6sgCFN9SP7BPc5Z3Fh9gMuBy
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Connection: keep-alive
< access-control-allow-origin: *
< content-type: application/json; charset=utf-8
< transfer-encoding: chunked
<
* Connection #0 to host localhost left intact
{"created_at":1647545791,"default_sorting_field":"","fields":[{"facet":true,"index":true,"infix":false,"locale":"","name":"brand","optional":false,"sort":false,"type":"string"}],"name":"watch_march_17","num_documents":0,"symbols_to_index":[],"token_separators":[]}
j
Hmm, I see
access-control-allow-origin: *
returned by the server. So I wonder why the browser is complaining
https://stackoverflow.com/a/44385327/123545 Suggests that
Access-Control-Allow-Methods
is by default set to allow GET HEAD POST requests. So may be that's why it's not working for DELETEs
We might have to add an explicit
Access-Control-Allow-Methods
header on the server-side to get this to work.
Could you open a Github issue for this?
1
r
Sure
j
Thanks @Roman Kovtun!
Btw, this is quite the coincidence, but you're the 555th member to join the Slack community and you also happened to open the 555th Github issue!
🚀 2
🎉 3
r
I was waiting for this moment my whole life 🙂
😂 2