I’m using Express js with @apollo/server
& installed various middleware e.g: morgan, cors, cookieParser. But they didn’t executed.
// required dependencies here
..........
// Multiple schema configured file
const mergedSchema = require('./schemas/schemaConfig');
// Apollo server connection build
const apolloserver = new ApolloServer({
schema: mergedSchema
})
// connection establishing
async function serverStart(server) {
const PORT = process.env.PORT || 2080
try {
const { url } = await startStandaloneServer(server, {
context: ({req, res}) => ({req, res}),
listen: { port: PORT }
})
console.log(`# ~Server ready at: ${url}`);
await mongoose.connect('mongodb://127.0.0.1:27017/DB-Name', {
useNewUrlParser: true
})
mongoose.set("strictQuery", false);
console.log("~Database connected.....");
} catch (error) {
console.log(error);
}
}
serverStart(apolloserver);
// applied middlewares
app.use(
morgan('dev'),
cors(),
express.json(),
cookieParser()
)
Applied middleware doesn’t executing e.g: Didn’t executed morgan logger, cookieParser() etc. I tried expressMiddleware()
with await server.start()
instead of await startStandaloneServer()
for managing middleware but facing another issues. When i’m going to await startStandaloneServer()
approach server started & working, but middleware’s not working expectedly.