Skip to content

Commit

Permalink
feat: added explorer endpoint with optional driveId param
Browse files Browse the repository at this point in the history
  • Loading branch information
froid1911 committed Feb 14, 2024
1 parent 22e4cef commit 9400243
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
23 changes: 15 additions & 8 deletions api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import expressPlayground from 'graphql-playground-middleware-express';
import { getChildLogger } from './logger';
import basePrisma from './database';
import { API_GQL_ENDPOINT } from './env';
import {
MiddlewareOptions,
renderPlaygroundPage,
} from 'graphql-playground-html'

const logger = getChildLogger({ msgPrefix: 'APP' });
const startupTime = new Date();
Expand All @@ -30,14 +34,17 @@ export const createApp = (): Express => {
});

app.get(
'/',
expressPlayground({
endpoint: API_GQL_ENDPOINT,
settings: {
'editor.theme': 'light',
'request.credentials': 'include',
},
}),
'/explorer/:driveId?',
(req, res) => {
res.setHeader('Content-Type', 'text/html')
const endpoint = API_GQL_ENDPOINT + (req.params.driveId !== undefined ? `/d/${req.params.driveId}` : '/drives')
res.send(renderPlaygroundPage({
endpoint: endpoint,
settings: {
'request.credentials': 'include',
},
}))
}
);

return app;
Expand Down
4 changes: 2 additions & 2 deletions api/src/env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export const PORT = process.env.PORT ?? "3000";
export const isDevelopment = process.env.NODE_ENV === "development";
export const AUTH_SIGNUP_ENABLED = Boolean(process.env.AUTH_SIGNUP_ENABLED);
export const JWT_EXPIRATION_PERIOD: string = getJwtExpirationPeriod();
export const API_ORIGIN = process.env.API_ORIGIN || `http://0.0.0.0:${PORT}`;
export const API_ORIGIN = process.env.API_ORIGIN || `http://localhost:${PORT}`;
export const API_GQL_ENDPOINT =
process.env.API_GQL_ENDPOINT || `${API_ORIGIN}/graphql`;
process.env.API_GQL_ENDPOINT || `${API_ORIGIN}`;
export const CORS_ORIGINS = process.env.ORIGINS?.split(",") ?? [
"https://studio.apollographql.com",
"https://ph-switchboard-nginx-prod-c84ebf8c6e3b.herokuapp.com",
Expand Down

0 comments on commit 9400243

Please sign in to comment.