Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Gets a list of all the cities that we get hits from
require('dotenv-safe').config()
const config = {
postgres: {
user: process.env.POSTGRES_USER,
host: process.env.POSTGRES_HOST,
database: process.env.POSTGRES_DATABASE,
password: process.env.POSTGRES_PASSWORD,
port: process.env.POSTGRES_PORT
}
}
const logger = require('loggy')
if (process.env.POSTGRES_ENABLED !== 'true') {
logger.error('Postgres is disabled')
process.exit(1)
}
// Load environment variables from .env in development and throw an
// error if any required variables are missing in production
require('dotenv-safe').config({
example:
process.env.NODE_ENV === 'production'
? '.env.prod.example'
: '.env.example',
});
const { logError } = require('./util/error-logger');
const app = require('./app');
app
.initialise()
.then(() => app.start())
.catch(logError);
// Inject the prefix onto the keys
required = Object.keys(required).reduce(
(memo, requiredKey) =>
Object.assign(memo, {
[`${ciEnvPrefix}${requiredKey}`]: required[requiredKey],
}),
{}
);
// write back to a temporary file
const tmpobj = tmp.fileSync();
fs.writeFileSync(tmpobj.fd, envfile.stringifySync(required));
// Use that temporary file as the 'expected env' vars
const envVars = dotEnvSafe.config({
example: tmpobj.name,
});
if (envVars.error) {
// TODO: Better error with info on how to set the correct env vars
throw new Error(envVars.error);
}
// The loaded env vars with the prefix removed
const loadedEnvVars = Object.keys(envVars.parsed)
.filter(key => key.startsWith(ciEnvPrefix))
.reduce(
(memo, key) =>
Object.assign(memo, {
[key.replace(ciEnvPrefix, '')]: envVars.parsed[key],
}),
config.options.devProxy = config.options.ssr;
const extraDefines = {
__SSR__: config.options.ssr,
__PERSIST_GQL__: `'${config.options.persistGraphQL}'`,
__FRONTEND_BUILD_DIR__: `'${config.options.frontendBuildDir}'`,
__DLL_BUILD_DIR__: `'${config.options.dllBuildDir}'`,
__DEBUGGING__: `'${debug}'`
};
if (process.env.NODE_ENV !== 'production') {
if (!config.options.ssr) {
console.log('Warning! exposing env variables in UI, only run in development.');
var dotenv = require('dotenv-safe')
.config(
{
allowEmptyValues: true,
path: process.env.ENV_FILE,
example: '../../config/development/dev.env',
});
const envConfig = {
plugins: [
new webpack.DefinePlugin({
"__ENV__": JSON.stringify(dotenv.parsed)
}),
],
}
config.builders.web.webpackConfig = merge(config.builders.web.webpackConfig, envConfig);
}
}
require('dotenv-safe').config({
example: '.env.test.example',
});
const signale = require('signale');
signale.disable();
require('dotenv-safe').config()
const logger = require('loggy')
const express = require('express')
const http = require('http')
const app = express()
const compression = require('compression')
app.use(compression())
const server = http.createServer(app)
const register = require('./register')
const checkForNewVersion = require('./updates')
app.use('/api/data', require('./api/data'))
function startWebServer () {
return new Promise((resolve, reject) => {
server.listen(process.env.WEBSERVER_PORT, err => {
require('dotenv-safe').config()
const path = require('path')
const UAParser = require('useragent')
const { Pool } = require('pg')
const pgDb = new Pool({
user: process.env.POSTGRES_USER,
host: process.env.POSTGRES_HOST,
database: process.env.POSTGRES_DATABASE,
password: process.env.POSTGRES_PASSWORD,
port: process.env.POSTGRES_PORT
})
const Database = require('better-sqlite3')
const sqliteDb = new Database(path.join(__dirname, '..', 'analytics.sqlite'))
const pgHandler = require('../server/api/analytics/PostgresAnalyticsHandler.js')
const getDotenvPlugin = (commonDotenvPath, localDotenvPath, isProduction) => {
const localDotenv = !isProduction ? dotenv.config({
example: null,
path: localDotenvPath,
}) : {}
const commonDotenv = dotenvSafe.config({
example: commonDotenvPath,
path: !isProduction ? commonDotenvPath : null,
})
return new webpack.EnvironmentPlugin([
...Object.keys(commonDotenv.required || {}),
...Object.keys(localDotenv.parsed || {}),
])
}