Skip to content

Commit

Permalink
feat: Add getActiveEnv function
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasdao committed Jul 20, 2017
1 parent 53f22b7 commit 07f0718
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
20 changes: 15 additions & 5 deletions src/webfunc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,25 @@ const path = require('path')
const fs = require('fs')
const httpError = require('http-errors')

let webconfig = null
let _webconfig = null
const getWebConfig = memoize => {
const skipMemoization = memoize == undefined ? false : !memoize
if (!skipMemoization || webconfig == null) {
if (!skipMemoization || _webconfig == null) {
/*eslint-disable */
const webconfigPath = path.join(process.cwd(), 'webconfig.json')
/*eslint-enable */
webconfig = fs.existsSync(webconfigPath) ? require(webconfigPath) : undefined
_webconfig = fs.existsSync(webconfigPath) ? require(webconfigPath) : undefined
}
return webconfig
return _webconfig
}

const getActiveEnv = memoize => {
const webconfig = getWebConfig(memoize)
const env = ((webconfig || {}).env || {}).active
if (env)
return Object.assign(webconfig.env, { _name: env })
else
return null
}

let headersCollection = null
Expand Down Expand Up @@ -106,5 +115,6 @@ module.exports = {
setResponseHeaders,
handleHttpRequest,
serveHttp,
getWebConfig
getWebConfig,
getActiveEnv
}
3 changes: 2 additions & 1 deletion templates/graphql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const executableSchema = makeExecutableSchema({
const graphqlOptions = {
schema: executableSchema,
graphiql: true,
endpointURL: "/graphiql"
endpointURL: "/graphiql",
context: {} // add whatever global context is relevant to you app
}

exports.{{entryPoint}} = serveHTTP(graphqlOptions)
6 changes: 3 additions & 3 deletions templates/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
"logs": "webfunc logs"
},
"dependencies": {
"webfunc": "^0.1.0-alpha",
"google-graphql-functions": "^0.1.0-alpha.5",
"google-graphql-functions": "^0.1.0-alpha",
"graphql": "^0.9.3",
"graphql-s2s": "^0.2.1",
"graphql-tools": "^0.11.0",
"lodash": "^4.17.4",
"http-errors": "^1.6.1",
"schemaglue": "^1.2.0"
"schemaglue": "^1.2.0",
"webfunc": "^0.1.0-alpha"
},
"devDependencies": {
"chai": "^4.1.0",
Expand Down

0 comments on commit 07f0718

Please sign in to comment.