Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions graphql/server/.env

This file was deleted.

5 changes: 5 additions & 0 deletions graphql/server/src/middleware/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ export const createApiMiddleware = (opts: any) => {
};
req.api = api;
req.databaseId = databaseId;
const schemaKey =
Array.isArray(schemas) && schemas.length ? schemas.join(',') : 'default';
Copy link
Contributor

Choose a reason for hiding this comment

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

hey @Zetazzz this code seems a bit new?

req.svc_key = (req as any).urlDomains?.domain
? getSvcKey(opts, req)
: `schemata:${databaseId ?? 'default'}:${schemaKey}`;
return next();
}
try {
Expand Down
8 changes: 1 addition & 7 deletions graphql/server/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,4 @@ import { getEnvOptions } from '@constructive-io/graphql-env';

import { GraphQLServer as server } from './server';

server(
getEnvOptions({
pg: {
database: process.env.PGDATABASE,
},
})
);
server(getEnvOptions());
18 changes: 8 additions & 10 deletions graphql/server/src/scripts/create-bucket.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
// Minimal script to create a bucket in MinIO using @constructive-io/s3-utils
// Avoid strict type coupling between different @aws-sdk/client-s3 versions

// Loads graphql/server/.env by default when running via ts-node from this workspace
import 'dotenv/config';

import { getEnvOptions } from '@constructive-io/graphql-env';
import { S3Client } from '@aws-sdk/client-s3';
import { createS3Bucket } from '@constructive-io/s3-utils';

const BUCKET = process.env.BUCKET_NAME || 'test-bucket';
const REGION = process.env.AWS_REGION || 'us-east-1';
const { cdn } = getEnvOptions();

const BUCKET = cdn?.bucketName ?? 'test-bucket';
const REGION = cdn?.awsRegion ?? 'us-east-1';
const ACCESS_KEY =
process.env.AWS_ACCESS_KEY || process.env.AWS_ACCESS_KEY_ID || 'minioadmin';
process.env.AWS_ACCESS_KEY_ID || cdn?.awsAccessKey || 'minioadmin';
const SECRET_KEY =
process.env.AWS_SECRET_KEY ||
process.env.AWS_SECRET_ACCESS_KEY ||
'minioadmin';
const ENDPOINT = process.env.MINIO_ENDPOINT || 'http://localhost:9000';
process.env.AWS_SECRET_ACCESS_KEY || cdn?.awsSecretKey || 'minioadmin';
const ENDPOINT = cdn?.minioEndpoint || 'http://localhost:9000';

(async () => {
try {
Expand Down
12 changes: 5 additions & 7 deletions graphql/server/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dotenv/config';

import { getEnvOptions } from '@constructive-io/graphql-env';
import { Logger } from '@pgpmjs/logger';
import { healthz, poweredBy, trustProxy } from '@pgpmjs/server-utils';
Expand Down Expand Up @@ -35,13 +33,13 @@ class Server {
this.opts = getEnvOptions(opts);

const app = express();
const api = createApiMiddleware(opts);
const authenticate = createAuthenticateMiddleware(opts);
const api = createApiMiddleware(this.opts);
const authenticate = createAuthenticateMiddleware(this.opts);

healthz(app);
trustProxy(app, opts.server.trustProxy);
trustProxy(app, this.opts.server.trustProxy);
// Warn if a global CORS override is set in production
const fallbackOrigin = opts.server?.origin?.trim();
const fallbackOrigin = this.opts.server?.origin?.trim();
if (fallbackOrigin && process.env.NODE_ENV === 'production') {
if (fallbackOrigin === '*') {
log.warn('CORS wildcard ("*") is enabled in production; this effectively disables CORS and is not recommended. Prefer per-API CORS via meta schema.');
Expand All @@ -57,7 +55,7 @@ class Server {
app.use(requestIp.mw());
app.use(api);
app.use(authenticate);
app.use(graphile(opts));
app.use(graphile(this.opts));
app.use(flush);

this.app = app;
Expand Down