Skip to content

Commit

Permalink
feat(discord): wip, add launch endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
shanedg committed Jun 17, 2024
1 parent 14ff184 commit 3364de2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/src/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ErrorCard } from './components/ErrorCard';
import { Footer } from './components/Footer';
import { Header } from './components/Header';
import { Home } from './components/Home';
import { NewWorld } from './components/NewWorld';
import { NewWorld } from './components/Launch';
import { WorldDetail } from './components/WorldDetail';
import { Worlds } from './components/Worlds';

Expand Down
File renamed without changes.
12 changes: 12 additions & 0 deletions client/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ export default (env = {}, argv = {}) => {
});
}
},
// Mock requests to launch a new world
{
name: 'mock-api-launch',
path: '/api/v1/launch',
middleware: (_request, response) => {
response.send({
instance: {
id: '<mocked_instance_id>',
},
});
}
},
// Mock requests for the world list
{
name: 'mock-api-worlds',
Expand Down
12 changes: 12 additions & 0 deletions discord/lib/authenticated-api/handle-launch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// import { fetchWithOauth } from '../utils/get-fetch-with-oauth';

// Middleware handler that responds to new launch requests
// FIXME: ANNOTATE PARAMETER TYPES
// TODO: TEST
export const handleLaunch = async (fetch, guildId, request, response, next) => {
// TODO: 1. check request for required data

// TODO: 2. run command to launch instance

next(new Error('nope!'));
};
7 changes: 7 additions & 0 deletions discord/lib/authenticated-api/handle-launch.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import test from 'ava';

// import { handleLaunch } from './handle-launch';

test('asdf', t => {
t.is(true, true);
});
4 changes: 4 additions & 0 deletions discord/lib/authenticated-api/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import express from 'express';
import { handleApiError } from './handle-api-error';
import { handleEndpointNotFound } from './handle-endpoint-not-found';
import { handleGetGuildMembership } from './handle-get-guild-membership';
import { handleLaunch } from './handle-launch';
import { requireAuthentication } from './require-authentication';
import { requireGuildMembership } from './require-guild-membership';

Expand Down Expand Up @@ -51,6 +52,9 @@ export class AuthenticatedAPIRouter {
// Deliver guild membership data to the frontend
authenticatedApiRouter.get('/authorized', handleGetGuildMembership);

// Accept requests to start up new servers
authenticatedApiRouter.post('/launch', handleLaunch.bind(null, this.configuration.fetch, this.configuration.guildId));

authenticatedApiRouter.use(handleApiError);

// Any unhandled requests at this point must be 404s
Expand Down

0 comments on commit 3364de2

Please sign in to comment.