async function main() { const app = await NestFactory.create(AppModule, { logger: process.env.NODE_ENV === 'development' ? new Logger() : false, }); await bootstrap(app); }
// Redirect a request to the root path to the main app app.use('/', (req: express$Request, res: express$Response) => { res.redirect( process.env.NODE_ENV === 'production' && !process.env.FORCE_DEV ? 'https://spectrum.chat' : 'http://localhost:3000' ); });
function initView(app) { const configService: ConfigService = app.get(ConfigService); const viewPath = path.join(__dirname, '../views'); app.setBaseViewsDir(viewPath); app.setViewEngine('njk'); const nunjucksEnv = nunjucks.configure(viewPath, { noCache: process.env.NODE_ENV === configService.DEVELOPMENT, autoescape: true, express: app, }); for (const key of Object.keys(viewfilter)) { nunjucksEnv.addFilter(key, viewfilter[key]); } // macro中不能访问当前 context , 将要访问的变量加到 global nunjucksEnv.addGlobal('env', configService.env); nunjucksEnv.addGlobal('jsPath', configService.static.jsPath); }
export default async function bootstrap(app, listening: boolean = true) { const configService: ConfigService = app.get(ConfigService); const myLoggerService: MyLoggerService = app.get(MyLoggerService); myLoggerService.info({ message: 'Starting Nest application...', data: { NODE_ENV: process.env.NODE_ENV, port: configService.server.port, }, }); app.useGlobalPipes(new ValidateDtoPipe(configService)); app.useGlobalInterceptors(new TransformResInterceptor(configService, myLoggerService)); app.useGlobalFilters(new GlobalExceptionFilter(configService, myLoggerService)); initView(app); if (listening) { await app.listen(configService.server.port); myLoggerService.info({ message: 'Nest application successfully started', }); } }
constructor() { const envConfigMap = { development: developmentJSON, test: testJSON, production: productionJSON, }; if (envConfigMap[process.env.NODE_ENV]) { _.merge(defaultJSON, envConfigMap[process.env.NODE_ENV]); this.env = process.env.NODE_ENV; } else { this.env = this.DEVELOPMENT; } this.db = new DBConfig(defaultJSON.db); if (this.env !== this.DEVELOPMENT && this.db.synchronize) { process.exit(-1); } this.redis = new RedisConfig(defaultJSON.redis); this.statsD = new StatsDConfig(defaultJSON.statsD); this.server = new ServerConfig(defaultJSON.server); this.static = new StaticConfig(defaultJSON.static); this.aliyunOSS = new AliyunOSSConfig(defaultJSON.aliyunOSS); this.aliyunSMS = new AliyunSMSConfig(defaultJSON.aliyunSMS); this.geetestCaptcha = new GeetestCaptcha(defaultJSON.geetestCaptcha); this.github = new GithubConfig(defaultJSON.github); this.weibo = new WeiboConfig(defaultJSON.weibo); }
function getClientEnvironment(publicUrl) { const raw = Object.keys(process.env) .filter(key => REACT_APP.test(key)) .reduce( (env, key) => { env[key] = process.env[key]; return env; }, { // Useful for determining whether we’re running in production mode. // Most importantly, it switches React into the correct mode. NODE_ENV: process.env.NODE_ENV || 'development', // Useful for resolving the correct path to static assets in `public`. // For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />. // This should only be used as an escape hatch. Normally you would put // images into the `src` and `import` them in code to get their paths. PUBLIC_URL: publicUrl, } ); // Stringify all values so we can feed into Webpack DefinePlugin const stringified = { 'process.env': Object.keys(raw).reduce((env, key) => { env[key] = JSON.stringify(raw[key]); return env; }, {}), }; return { raw, stringified }; }
function setupGithub({ server }) { const dev = process.env.NODE_ENV !== 'production';
export default function CheckNodeEnv(expectedEnv) { if (!expectedEnv) { throw new Error('"expectedEnv" not set'); } if (process.env.NODE_ENV !== expectedEnv) { console.info( chalk.whiteBright.bgRed.bold( `"process.env.NODE_ENV" must be "${expectedEnv}" to use this webpack config` ) ); process.exit(2); } }
/** * Setup enviroment. */ let setupEnv = function (app: Application, args: {env: string}) { app.set(Constants.RESERVED.ENV, args.env || process.env.NODE_ENV || Constants.RESERVED.ENV_DEV, true); }
if (process.env.NODE_ENV !== 'test') { middleware.push(logger);
heapUsed: hemera.load.heapUsed, rss: hemera.load.rss, nodeEnv: process.env.NODE_ENV, uptime: process.uptime(), ts: Date.now()
process.env.NODE_ENV === 'development' ? subMenuViewDev : subMenuViewProd;
process.env.NODE_ENV === 'development' ? [
/** * Subscription socket has connected */ async onSubConnected() { if (process.env.NODE_ENV === "development") console.log("[Subscription] connected"); this.dispatch(appOperations.setSubscribed({ isSubscribed: true })); }
app.listen(port, () => { logger.info( `start express server at ${port} with ${process.env.NODE_ENV} mode at public path = ${publicPath}`, ); });