-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Site: Attach Database #2572
Site: Attach Database #2572
Conversation
site/src/routes/repl/index.svelte
Outdated
|
||
repl.set({ components }); | ||
} else { | ||
console.warn('TODO: 404 Gist') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't see how to plug in to the REPL's error toasts
const storageKey = 'svelte-dev:token'; | ||
|
||
// On load, get the last-known user token (if any) | ||
// Note: We can skip this all by writing User data? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have the complete user object. We could write it to localStorage and have the user-data immediately available. If/when this is the case, we fetch the /auth/me.json
endpoint which will wipe/reset if the token was expired or invalid.
export function toUser(obj={}) { | ||
const { uid, username, name, avatar } = obj; | ||
const token = sign({ uid, username }); | ||
return { uid, username, name, avatar, token }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only user data that ever makes it to the client. The uid
is GitHub's internal ID for the user. Not sure how "okay" it to keep this in localStorage.
Currently we don't. See comment above.
This is ready to be looked at~ |
Without looking at anything yet, I guess my main concern is will this mess up people running the site locally and trying to load stuff from the database? When someone posts a gist as part of a bug report, as part of testing my fix I will often run the site locally and check the REPL with my local copy of Svelte to see if the thing is fixed. I can create the secret keys or whatever is needed in my |
I would feel that's a very small edge case? Perhaps just you? lol They'd still post a gist link that can be opened on the live site by anybody. There is a slightly greater barrier of entry for local development, but presumably anyone who's wanting to contribute to the site is already willing to cross that threshold anyway. |
This looks 😎. Couple of thoughts before merging:
|
If you get an error
|
This is maybe a minor thing but I like the fact that you can double click a gist ID in the URL bar to select the whole thing. With |
oh wow, I just learned the hyphens are optional. We can just remove them from the URL. Don't mind me |
2a) Sure, I would probably want to query GistHub for the gist on server's 404. IMO, the 2b) I don't recall the gist's data from GitHub API, but I think the account/owner is included. The only non-public (at least, I think it's not "public") information we need is the
|
Yeah, I just realised that the account info is included, so we could create user objects if necessary when the gist is fetched, and add a token later if that user logs in, if we updated the DB automatically when the gist was requested. I guess it's a question of whether it's worse to increase the risk hitting API rate limits (because of requesting the same gist repeatedly), or to fill up the database unnecessarily. What's the argument for keeping the URLs the same, if we redirect the old to the new? |
Cool. We can create the gist immediately. Filling out our DB is very cheap & more forgiving than GH's rate limit. Just, familiarity. Avoiding redirects is also nice. They're still "gists" – it's just that they live in our domain now |
Cool. Working on this stuff atm — doing it in a separate branch off of this one in case any of it turns out controversial |
Ah okay. I was thinking I was assigned :P Am around if you wanna ping |
Ha, I'm being a little selfish — just figured you might have better things to do and that it'd be a good opportunity for me to fully wrap my head round the new stuff |
Haha, agreed – good opportunity. Not a problem at all~ |
add database entries for new gists, update REPL URLs
I can't seem to deploy this... getting the following error:
@lukeed any clue how to debug this? There doesn't seem to be anything useful in the logs, but I might be looking in the wrong place |
I ran it from the Docker image directly. Here was the message:
This was my fault. I removed it in this PR though am not sure where it's being used. Investigate later when not so tired. In the meantime, I pushed up a fix to master directly am now redeploying the site. |
users
table on PostgreSQL databaseAll in all, this removes the flakiness of:
tunneling public/anonymous traffic through GitHub's free quota
AKA, at launch, so many people were getting (silent) rate-limit errors. No content appeared.
disappearing sessions, as the source of truth has moved to a long-lasting DB instance.
Currently, sessions get wiped on every new deployment & on new and/or dying GCR instances
I've also added a
.env.example
file to keep easier track of what's needed. Of course,NODE_ENV
andPORT
are optional, but still listed anyway.Finally, I've already provisioned & migrated a DB instance for the website. The ENV vars are also already injected into GCR. Same goes for JWT configuration. Nothing else needs to be done for deployment if/when this is ready to go.
To run this locally, you need
postgres
installed. Then you need to create a new database and fill in the details as theDATABASE_URL
key within.env
file. Then you'll need to migrate/setup the database.Full instructions may look like this:
Here's an example
DATABASE_URL
value for localhost:# file: .env DATABASE_URL=postgres://lukeed@127.0.0.1:5432/svelte_demo
These ENV keys must be filled in in order to have a working app: