Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/graphql / src / index.ts
Size: Mime:
import portscanner from 'portscanner'
import { createApp, schema } from './app'
import { isPortFree } from './deps/isPortFree'

/**
 * is happening 2x...
 */
function startStandalone() {
  if (process.env.IS_STANDALONE_GRAPHQL) {
    console.log('[uxui-graphql] creating app...')
    const app = createApp()
    console.log('[uxui-graphql] about to listen...')

    const port = process.env.PORT || '4000'
    const host = process.env.HOST || 'localhost'

    // if (isPortFree(port)) {
    //   const listener = app.listen(parseInt(process.env.PORT, 10) || 4000, () => {
    //     console.log('[uxui-graphql] listening on port 4000')
    //   })

    //   console.log('[uxui-graphql] async after listening')

    //   process.on('SIGTERM', () => {
    //     console.log('[uxui-graphql] SIGTERM')
    //     listener.close()
    //   })
    // }

    portscanner.checkPortStatus(port, (err, status) => {
      if (err) {
        console.error(err)
      }
      if (status === 'closed') {
        const listener = app.listen(parseInt(port, 10), host, () => {
          console.log('[uxui-graphql] listening on port 4000')
        })

        console.log('[uxui-graphql] async after listening')

        process.on('SIGTERM', () => {
          console.log('[uxui-graphql] SIGTERM')
          listener.close()
        })
      }
    })
  } else {
    console.log('[uxui-graphql] NOT standalone')
  }
}

startStandalone()

// import { ApolloEngine } from 'apollo-engine'
// @todo try try again
// const engine = new ApolloEngine({
//   apiKey: 'service:skava-engine:_oygzZUWfir8gDOh7kpgAQ',
//   logging: {
//     level: 'INFO',
//   },
// })
// Start the server
// engine.listen({
//   port: 4000,
//   expressApp: app,
// })

export { startStandalone, schema }