Skip to content

Set up Docker env for local development#27

Draft
MCGallaspy wants to merge 6 commits into
smogon:masterfrom
MCGallaspy:dockerate-it
Draft

Set up Docker env for local development#27
MCGallaspy wants to merge 6 commits into
smogon:masterfrom
MCGallaspy:dockerate-it

Conversation

@MCGallaspy
Copy link
Copy Markdown
Contributor

This PR adds a docker files and compose spec, to enable quickly setting up a dev environment for loginserver testing.
Right now, it starts a loginserver instance, mapping port 8080 on the container to the host, along with a cockroachdb instance.

By running docker compose up --build --watch you will build and start both services and can monitor their combined logs on the console. Changing the source files will trigger a rebuild (aka hot reloading).

@MCGallaspy MCGallaspy marked this pull request as draft October 17, 2024 17:26
Comment thread src/actions.ts
return {password: pw};
},

async 'replays/batch.json'(params) {
Copy link
Copy Markdown
Member

@mia-pi-git mia-pi-git Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strike the .json from the name, for loginserver APIs we don't use that.

Comment thread src/actions.ts
const ids: string[] = params.ids.split(',');
const results = await Replays.getBatch(ids);
console.log(params, ids, results);
this.response.setHeader('Content-Type', 'application/json');
Copy link
Copy Markdown
Member

@mia-pi-git mia-pi-git Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.response.setHeader('Content-Type', 'application/json');

This is already handled by the loginserver under the hood.

Comment thread src/actions.ts
const results = await Replays.getBatch(ids);
console.log(params, ids, results);
this.response.setHeader('Content-Type', 'application/json');
return JSON.stringify(results);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return JSON.stringify(results);
return results;

This is also handled by the loginserver under the hood.

Comment thread src/actions.ts
if (!params.ids) {
throw new ActionError("Invalid batch replay request, must provide ids");
}
const ids: string[] = params.ids.split(',');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably this should be programatically capped in length here in addition to the query.

Copy link
Copy Markdown
Member

@mia-pi-git mia-pi-git left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the batch API endpoint into a new PR. Additionally, I've left feedback on that code.

Comment thread src/replays.ts Outdated
Comment on lines +244 to +246
return replays.selectAll(
SQL`*`
)`WHERE private = 0 AND id IN (${idsForQuery}) LIMIT 51`.then(this.toReplays);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return replays.selectAll(
SQL`*`
)`WHERE private = 0 AND id IN (${idsForQuery}) LIMIT 51`.then(this.toReplays);
return replays.selectAll()`WHERE private = 0 AND id IN (${idsForQuery}) LIMIT 51`.then(this.toReplays);

This is only necessary if you're not selecting * - it defaults to * otherwise.

SQL magic can just take a list, and the right thing
will happen. No need to construct a string.
Prevents rebuild when writing e.g. logs to base dir.
@MCGallaspy
Copy link
Copy Markdown
Contributor Author

I'll cherry-pick the batch endpoint changes onto a new branch.

@MCGallaspy
Copy link
Copy Markdown
Contributor Author

@mia-pi-git see #28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants