fetch('/categories') ¿? #13
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
2 participants
Due date
No due date set.
Dependencies
No dependencies set.
Reference: playsearch.kaki87.net/v1#13
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why the line
fetch('/categories').then(res => res.json()).then(res => res.forEach(c => document.querySelector('#category').innerHTML +=
<option value="${c}">${c[0]}${c.slice(1).replace(/_/g, ' ').toLowerCase()}</option>));it throws:
Failed to load resource: the server responded with a status of 404
So that the path (Categories/ does not exist on root
e.g. http://localhost:52558/categories
Also throws error:
Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
Promise.then (async)
(anonymous) @ index.js:6
Something is not right with your setup.
Please restart from the beginning and tell me exactly how you're doing it.
Same as #15,
/categoriesis not a static file but an HTTP route that you can find atindex.js:13.STEPS that I do:
I installed NodeJs, Yean, Git
I Downloaded your files, extracted your project in:
C:\Production\KPlaySearch-master\kplaysearch\
I ran:
C:\Production\KPlaySearch-master\kplaysearch\yarn install
then:
C:\Production\KPlaySearch-master\kplaysearch>yarn start
yarn run v1.22.5
$ node index.js
Server running
Then when I run localhost in :
C:\Production\KPlaySearch-master\kplaysearch\public
Running index.html runs attached error:
index.js:6 GET http://localhost:56337/categories 404 (Not Found
And if I try to search say: "Explorer" I do not get any results and get:
index.js:34 POST http://localhost:56337/search 404 (Not Found)
So by the way, code as you provided by default does not work
What do you mean by that exactly ?
I meant that setting up a website in IIS under the root directory of :
C:/ .... KPlaySearch(extractedprojectfiles)/public
(in my case e.g.: C:\Production\KPlaySearch-master\kplaysearch\public)
Dont work as show in pictures, say new attached picture
You're not supposed to do that.
fastifyis a server of its own.If you look at the code (
index.js:27), you'll see that the script creates an HTTP server on port3030.I guess I could have put it in a config file or as an environment variable but I didn't used to bother doing that at the time.
So, you'll access it at
http://localhost:3030/, and everything will work as expected.As I said,
/searchand/categoriesare fastify routes, called by fetch requests, respectively in POST and GET, returning JSON data. Those are detailed in the main script.The only folder containing static files is
/public.Plus, the log output
Server runningshould have made you realize this ^^Done, using localhost:3030
But I cannot run on my own localhost used by Visual Studio 2019 (IIS based)
Well, it's not like PHP where whe have static files everywhere.
Welcome to Node.