Skip to content
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

add maxFileSize #5570

Merged
merged 4 commits into from
Apr 29, 2021
Merged
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
5 changes: 5 additions & 0 deletions .changeset/shiny-snakes-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': minor
---

Added `maxFileSize` property to keystone config.
2 changes: 2 additions & 0 deletions docs/pages/apis/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ Options:
- `cors` (default: `undefined`): Allows you to configure the [cors middleware](https://www.npmjs.com/package/cors#configuration-options) for your Express server.
If left undefined `cors` will not be used.
- `port` (default: `3000` ): The port your Express server will listen on.
- `maxFileSize` (default: `200 * 1024 * 1024`): The maximum file size allowed for uploads. If left undefined, defaults to `200 MiB`

```typescript
export default config({
server: {
cors: { origin: ['http://localhost:7777'], credentials: true }:
port: 3000
maxFileSize: 200 * 1024 * 1024
},
/* ... */
});
Expand Down
9 changes: 8 additions & 1 deletion packages-next/keystone/src/lib/server/createExpressServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import type { KeystoneConfig, CreateContext, SessionStrategy } from '@keystone-n
import { createAdminUIServer } from '@keystone-next/admin-ui/system';
import { createApolloServerExpress } from './createApolloServer';

const DEFAULT_MAX_FILE_SIZE = 200 * 1024 * 1024; // 200 MiB

const addApolloServer = ({
server,
config,
graphQLSchema,
createContext,
sessionStrategy,
apolloConfig,
}: {
server: express.Express;
config: KeystoneConfig;
graphQLSchema: GraphQLSchema;
createContext: CreateContext;
sessionStrategy?: SessionStrategy<any>;
Expand All @@ -26,7 +30,9 @@ const addApolloServer = ({
sessionStrategy,
apolloConfig,
});
server.use(graphqlUploadExpress());

const maxFileSize = config.server?.maxFileSize || DEFAULT_MAX_FILE_SIZE;
server.use(graphqlUploadExpress({ maxFileSize }));
// FIXME: Support custom API path via config.graphql.path.
// Note: Core keystone uses '/admin/api' as the default.
apolloServer.applyMiddleware({ app: server, path: '/api/graphql', cors: false });
Expand Down Expand Up @@ -57,6 +63,7 @@ export const createExpressServer = async (
if (isVerbose) console.log('✨ Preparing GraphQL Server');
addApolloServer({
server,
config,
graphQLSchema,
createContext,
sessionStrategy,
Expand Down
2 changes: 2 additions & 0 deletions packages-next/types/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ export type ServerConfig = {
cors?: CorsOptions | true;
/** Port number to start the server on. Defaults to process.env.PORT || 3000 */
port?: number;
/** Maximum upload file size allowed (in bytes) */
maxFileSize?: number;
};

// config.graphql
Expand Down