dyedgreen / deno-sqlite

Deno SQLite module
https://deno.land/x/sqlite
MIT License
409 stars 36 forks source link

how do you connect from an SPA desktop ~.html app to a deno-sqlite server.js file? #161

Closed gounaman closed 2 years ago

gounaman commented 2 years ago

Sorry for the intro / beginner level of this issue, but...

this works great if U connect to sqlite from a js server file on Windows 11

However I cannot find any documentation +++ anywhere ++ that shows how an html/css/js SPA can connect to a Deno js local server file

i can render the html/css part of my html app by running from the command line my ~.js server file

but I cannot connect or get a response going the other way or have it do anything in terms of the database

instead i get this error

Access to script at 'file:///C:/Users/xxx/Desktop/DENO/deno_server/server.js%3Eimport%20%7B%20DB%20%7D%20from' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.

the script tag of my SPA html file looks like this

<script type ="module" src="C:\Users\xxx\Desktop\DENO\deno_server\server.js>

the Deno server file looks like this

`import { serve } from "https://deno.land/std/http/server.ts"; import { DB } from "https://deno.land/x/sqlite/mod.ts";

const server = Deno.listen({ port: 8080 }); console.log(Porto is running.);

for await (const server_request of server) { const _file = await Deno.readFile('./index.html'); const decoder = new TextDecoder(); server_request.respond({ body: decoder.decode(_file) })};`

A very simple working example code would be most helpful to anyone (ie newbies like me!) unfamiliar with Deno. that shows exactly how to connect to this Deno module form a .html file that contains a JS script

Much appreciated. Thank you!