03-22-25
This morning I woke up with sore arms, crusty eyes, and an
overall feeling of satisfaction after cobbling together my
sticker organizing script yesterday. But then I checked it on
neocities and - wow! - it doesn't work... apparently
you can't just make a request to get all the files in a
private neocities folders without verifying that you should be
accessing that folder
|
success is on hold |
XMLHttpRequest
On neocities getting neocities has an api!
GET /api/list
|
why is it failing? |
Testing using Test works with authentication! Testing call from local server now. Hmm but I need to pass the auth info in the code but keep it a secret. its not a good idea to store secrets/sensitive data in javascript because its client side & once the code is uploaded & hosted on a server someone can inspect the javascript (if it's inline) or the network call & get that data.
client side
part of an application that runs on the users device (laptop, tablet, phones, etc). html ,
css , & js are all client-side
languages
Seems the safest option is to store the info on a
different server off neocities or github & fetch it before
making the request. If neocities offered a secrets tab in
the account settings that would be nice but it doesn't
I did not realize finding somewhere to host secret variables would be this big of a task. I've been researching for an hour and so far the solutions are too complicated for my needs. I dont want to encrypt anything, or build my own server, or install a library. uugh I found a solution that I dont like, but it'll do for now. |
testing |
CORS is truly the bane of my existence. I forgot to hate it.
Why did I forget to hate it? Every.
Single. Request - even those that
DONT need authentication fails with a
I try adding
I try 3 different browser extensions that set the CORS header
so I don't have to
I try altering the settings of my local server so that the server can set the CORS header because (as I've learned through furious googling) the header can only be set from server side, but I don't know how to access the server config... cors sucks ![]() |
DAMN IT CORS!!
|
CORS - Cross Origin Resource Sharing
lets a server decide if other origins (domain, port, scheme) can load its resources/data
Sooo the
Ok so with CORS if the server that is recieving the
request doesn't return
Both values have the same
scheme,
domain, &
port.
The scheme is different between
origins. The origin on the left is using
|
ok so wtf is CORS? |
Browsers make a "preflight" request to the server hosting the cross-origin resource by sending headers indicating the HTTP method & headers that will be used in the actual request to see if that server will allow the browsers request.
Cross origin resources are the headers
A preflight request is an
Simple requests like Cross-origin HTTP requests initiated from JS scripts are restricted for security reasons
So my current request is coming from a local server, which has a different domain, scheme, & origin than neocities.org, so all requests from my server to their server will fail.
Interestingly the browser will perform a network fetch to
the other origin to check for the CORS header, and even if
it successfully gets the data it won't let the JS code
access the data if the CORS header is missing... so the
request
could succeed without the response header, but with
JS I cannot access that data.
|
pre-flight requests |
![]()
I'm still confused about most things but I think I can work
with this info. I can't do what I want with my current setup
Looks like lots of people have been asking for CORS response header to be added, but there's no followup after 2020 from the developers. Github Issue Link I'll try setting up a server I guess. It seems like a good long term solution & I'll learn a new skill which is always fun after several weeks of frustration. Neocities Node Server Doc. In the mean time I'll just add the stickers manually. |
what to do now? |