@srsl/tools
Version:
JavaScript tools for common interfaces
45 lines (38 loc) • 1.25 kB
JavaScript
const http = require('http')
const express = require('./express')
const EXPRESS_PORT = process.env.EXPRESS_PORT || 8000
module.exports = async (context) => {
const {
routes,
views,
apolloServerExpress,
sequelize,
session,
...rest
} = context
// TODO - https://www.npmjs.com/package/express-swagger-generator, https://github.com/pgroot/express-swaggerize-ui
console.log('[Express] Creating Express app.')
const app = await express({
routes,
views,
sequelize,
session,
})
const httpServer = http.createServer(app)
if (apolloServerExpress) {
apolloServerExpress.applyMiddleware({ app, path: '/graphql' })
apolloServerExpress.installSubscriptionHandlers(httpServer)
}
httpServer.listen(EXPRESS_PORT, (values) => {
console.log(`[Express] Server listening on EXPRESS_PORT ${EXPRESS_PORT}`)
if (apolloServerExpress) {
console.log(`[Express] 🚀 Apollo GraphQL Server ready at http://127.0.0.1:${EXPRESS_PORT}${apolloServerExpress.graphqlPath}`)
console.log(`[Express] 🚀 Apollo GraphQL Subscriptions ready at ws://127.0.0.1:${EXPRESS_PORT}${apolloServerExpress.subscriptionsPath}`)
}
})
return {
apolloServerExpress,
app,
httpServer,
}
}