Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
feat: allow execution of custom express middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Pallas committed Feb 14, 2021
1 parent 2c647b0 commit 23145c5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
11 changes: 6 additions & 5 deletions packages/gateway/src/server/express.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import express from 'express';
import { ConnectionOptions, createConnection } from 'typeorm';
import { buildSchema } from 'type-graphql';
import {
ApolloServer,
AuthenticationError,
SchemaDirectiveVisitor,
} from 'apollo-server-express';
import { ApolloServer, SchemaDirectiveVisitor } from 'apollo-server-express';
import { BuildContext, ShatterContext } from '@shattercms/types';
import { authMiddleware } from './middleware';

export const startServer = async (context: BuildContext) => {
const app = express();

// Execute user express middleware
context.config.expressMiddlewares.forEach((middleware) => {
app.use(middleware);
});

// Create database connection
const orm = await createConnection({
...context.config.postgres,
Expand Down
1 change: 1 addition & 0 deletions packages/gateway/src/setup/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const configDefault: ShatterConfig = {
rootDir: '.',
debug: false,
modules: [],
expressMiddlewares: [],
server: {
host: 'localhost',
port: 4000,
Expand Down
3 changes: 2 additions & 1 deletion packages/types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Connection, EntitySchema } from 'typeorm';
import { SchemaDirectiveVisitor } from 'apollo-server-express';
import { Request, Response } from 'express';
import { Request, RequestHandler, Response } from 'express';
import { CorsOptions, CorsOptionsDelegate } from 'cors';

export interface ShatterConfig {
rootDir: string;
debug: boolean;

modules: Array<ConfigModule>;
expressMiddlewares: Array<RequestHandler>;

server: {
host: string;
Expand Down

0 comments on commit 23145c5

Please sign in to comment.