process#env TypeScript Examples

The following examples show how to use process#env. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: cdk-stack.ts    From laravel-on-aws-ecs-workshops with Apache License 2.0 6 votes vote down vote up
deploymentEnv = {
  type: process.env.THIS_DEPLOYMENT_ENV || "",
  namespace: process.env.THIS_DEPLOYMENT_NAMESPACE || "",
  domainName: process.env.THIS_DEPLOYMENT_DOMAINNAME || "",
  logStreamPrefix: process.env.THIS_LOG_STREAM_PREFIX || "",
  ecrRepoName: process.env.THIS_ECR_REPO_NAME || "",
  appName: process.env.APP_NAME || "",
  kmsKeyId: process.env.THIS_AWS_KMS_KEY_ID || "",
}
Example #2
Source File: set_env.ts    From Elastos.Essentials.App with MIT License 6 votes vote down vote up
devEnv = {
  production: false,
  EssentialsAPI: {
    serviceUrl: localEnv.NG_APP_ESSENTIALS_API_SERVICE_URL || prodEnv.EssentialsAPI.serviceUrl
  },
  RedPackets: {
    webUrl: env.ESSENTIALS_RED_PACKETS_WEB_URL || prodEnv.RedPackets.webUrl,
    serviceUrl: env.ESSENTIALS_RED_PACKETS_SERVICE_URL || prodEnv.RedPackets.serviceUrl
  },
  CredentialsToolbox: {
    serviceUrl: env.ESSENTIALS_CREDENTIALS_TOOLBOX_SERVICE_URL || prodEnv.CredentialsToolbox.serviceUrl
  }
}
Example #3
Source File: request.spec.ts    From genshin-kit-node with Apache License 2.0 6 votes vote down vote up
describe('request.ts', () => {
  const app = new GenshinKit()
  app.loginWithCookie(env.HOYOLAB_COOKIE as string)

  it('Get user game role by cookie', async () => {
    let res = await app.request(
      'get',
      'https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie'
    )
    const user = res.data.list.find((item: any) =>
      ['hk4e_cn', 'hk4e_global'].includes(item.game_biz)
    )
    res = await app.request('get', 'index', {
      role_id: user.game_uid,
      server: user.region,
    })
    expect(res.retcode).to.equal(0)
  })
})
Example #4
Source File: auto_select_ios_device.ts    From Elastos.Essentials.App with MIT License 5 votes vote down vote up
// eslint-disable-next-line require-await
void (async () => {
  let stdout = execSync("ionic cordova run ios --list --json").toString();

  // Remove the strange [native-run] prefix on every line
  let cleanJsonStr = stdout.replace(/\[native-run\]/g, "");

  /**
   * {
      devices: [],
      virtualDevices: [
        {
          platform: 'ios',
          name: 'iPad (8th generation)',
          sdkVersion: '14.3',
          id: 'E7D3ACFD-11A7-4681-BDEB-AF40B5147906'
        },
      ]
    }
   */
  let rawDevices = JSON.parse(cleanJsonStr);

  let virtualDevicesToUse: { id: string; name: string; sdkVersion: string }[] = rawDevices.virtualDevices.filter(vd => (
    vd.name as string).indexOf("iPhone") >= 0);

  /**
   * Automatically finds and returns the ios device ID based on the following order:
   * - if env.ESSENTIALS_IOS_RUN_DEVICE is set and exists, use this one
   * - Find "iPhone XX Pro Max" devices. Among them, find the highest number (most recent iphone)
   */

  let deviceId: string = null;
  if (env.ESSENTIALS_IOS_RUN_DEVICE) {
    let targetDeviceId = env.ESSENTIALS_IOS_RUN_DEVICE;
    let device = virtualDevicesToUse.find(d => d.id === targetDeviceId);
    if (device)
      deviceId = device.id;
  }

  // Fallback: default strategy
  if (!deviceId) {
    let proMaxIPhones: { id: string; name: string; version: number; sdkVersion: number }[] = [];
    for (let d of virtualDevicesToUse) {
      let verifier = new RegExp(/iPhone ([0-9]+) Pro Max/gm).exec(d.name);
      if (verifier) {
        proMaxIPhones.push({
          id: d.id,
          name: d.name,
          version: parseInt(verifier[1]),
          sdkVersion: parseFloat(d.sdkVersion)
        })
      }
    }

    // Sort by version DESC, and in case of equality, sdk version DESC
    proMaxIPhones.sort((a, b) => {
      if (a.version === b.version)
        return b.sdkVersion - a.sdkVersion;

      return b.version - a.version;
    });

    // The winner is the first item in the array
    deviceId = proMaxIPhones[0].id;
  }

  console.log(deviceId);
  process.exit(0);
})();
Example #5
Source File: modules.spec.ts    From genshin-kit-node with Apache License 2.0 5 votes vote down vote up
app.loginWithCookie(env.HOYOLAB_COOKIE as string)
Example #6
Source File: cdk-stack.ts    From laravel-on-aws-ecs-workshops with Apache License 2.0 4 votes vote down vote up
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);


    //---------------------------------------------------------------------------
    // VPC
    const vpc = new ec2.Vpc(this, generateName('VPC'), {
      maxAzs: 2,
      natGateways: 1,
      subnetConfiguration: [
        {
          cidrMask: 24,
          name: generateName('ingress'),
          subnetType: ec2.SubnetType.PUBLIC,
        },
        {
          cidrMask: 24,
          name: generateName('application'),
          subnetType: ec2.SubnetType.PRIVATE,
        },
        {
          cidrMask: 24,
          name: generateName('database'),
          subnetType: ec2.SubnetType.ISOLATED,
        },
      ],
    });

    //---------------------------------------------------------------------------
    // ECS

    // ECS Cluster
    const ecsCluster = new ecs.Cluster(this, 'LaravelWorkshopCluster', {
      vpc: vpc
    });
    const asg = ecsCluster.addCapacity('DefaultAutoScalingGroup', {
      instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.SMALL),
      maxCapacity: 4,
      minCapacity: 2,
    });

    // TODO: T4g

    // Task Definition
    const ec2TaskDefinition = new ecs.Ec2TaskDefinition(this, 'DefaultTaskDef');

    const ecrRepo = ecr.Repository.fromRepositoryName(this, 'DefaultRepo', deploymentEnv.ecrRepoName);

    const kmsKey = kms.Key.fromKeyArn(
      this, 
      generateName('kmsKey'), 
      'arn:aws:kms:' + props?.env?.region + ':' + props?.env?.account + ':key/' + deploymentEnv.kmsKeyId
    );

    const container = ec2TaskDefinition.addContainer('defaultContainer', {
      image: ecs.ContainerImage.fromEcrRepository(ecrRepo), 
      memoryLimitMiB: 512,
      cpu: 256,
      logging: new ecs.AwsLogDriver({
        streamPrefix: deploymentEnv.logStreamPrefix,
        logRetention: logs.RetentionDays.SIX_MONTHS,
      }),
      secrets: { // Retrieved from AWS Secrets Manager or AWS Systems Manager Parameter Store at container start-up.
        'APP_NAME'          : ecsValueFromSsmParameterString(this, 'APP_NAME'),
        'APP_ENV'           : ecsValueFromSsmParameterString(this, 'APP_ENV'),
        'APP_KEY'           : ecsValueFromSsmParameterSecureString(this, 'APP_KEY', kmsKey),
        'APP_DEBUG'         : ecsValueFromSsmParameterString(this, 'APP_DEBUG'),
        'APP_URL'           : ecsValueFromSsmParameterString(this, 'APP_URL'),

        'LOG_CHANNEL'       : ecsValueFromSsmParameterString(this, 'LOG_CHANNEL'),

        'DB_CONNECTION'     : ecsValueFromSsmParameterString(this, 'DB_CONNECTION'),
        'DB_HOST'           : ecsValueFromSsmParameterString(this, 'DB_HOST'),
        'DB_PORT'           : ecsValueFromSsmParameterString(this, 'DB_PORT'),
        'DB_DATABASE'       : ecsValueFromSsmParameterString(this, 'DB_DATABASE'),
        'DB_USERNAME'       : ecsValueFromSsmParameterSecureString(this, 'DB_USERNAME', kmsKey),
        'DB_PASSWORD'       : ecsValueFromSsmParameterSecureString(this, 'DB_PASSWORD', kmsKey),

        'BROADCAST_DRIVER'  : ecsValueFromSsmParameterString(this, 'BROADCAST_DRIVER'),
        'CACHE_DRIVER'      : ecsValueFromSsmParameterString(this, 'CACHE_DRIVER'),
        'QUEUE_CONNECTION'  : ecsValueFromSsmParameterString(this, 'QUEUE_CONNECTION'),
        'SESSION_DRIVER'    : ecsValueFromSsmParameterString(this, 'SESSION_DRIVER'),
        'SESSION_LIFETIME'  : ecsValueFromSsmParameterString(this, 'SESSION_LIFETIME'),

        'REDIS_HOST'        : ecsValueFromSsmParameterString(this, 'REDIS_HOST'),
        'REDIS_PASSWORD'    : ecsValueFromSsmParameterSecureString(this, 'REDIS_PASSWORD', kmsKey),
        'REDIS_PORT'        : ecsValueFromSsmParameterString(this, 'REDIS_PORT'),

        'MAIL_DRIVER'       : ecsValueFromSsmParameterString(this, 'MAIL_DRIVER'),
        'MAIL_HOST'         : ecsValueFromSsmParameterString(this, 'MAIL_HOST'),
        'MAIL_PORT'         : ecsValueFromSsmParameterString(this, 'MAIL_PORT'),
        'MAIL_USERNAME'     : ecsValueFromSsmParameterSecureString(this, 'MAIL_USERNAME', kmsKey),
        'MAIL_PASSWORD'     : ecsValueFromSsmParameterSecureString(this, 'MAIL_PASSWORD', kmsKey),
        'MAIL_ENCRYPTION'   : ecsValueFromSsmParameterString(this, 'MAIL_ENCRYPTION'),
        'MAIL_FROM_ADDRESS' : ecsValueFromSsmParameterString(this, 'MAIL_FROM_ADDRESS'),
        'MAIL_FROM_NAME'    : ecsValueFromSsmParameterString(this, 'MAIL_FROM_NAME'),
        
        'ZZZ_KEY'           : ecsValueFromSsmParameterSecureString(this, 'ZZZ_KEY', kmsKey),
      },      
    });

    container.addPortMappings({
      containerPort: 80,
      protocol: ecs.Protocol.TCP
    });

    // ECS Service
    const ecsService = new ecs.Ec2Service(this, 'DefaultService', {
      cluster: ecsCluster,
      taskDefinition: ec2TaskDefinition,
      desiredCount: 2,
    });

    //---------------------------------------------------------------------------
    // Cert
    const domainAlternativeName = '*.' + deploymentEnv.domainName;
    const cert = new acm.Certificate(this, generateName('Cert'), {
      domainName: deploymentEnv.domainName,
      subjectAlternativeNames: [domainAlternativeName],
      validation: acm.CertificateValidation.fromDns(), // Records must be added manually
    });

    //---------------------------------------------------------------------------
    // ALB
    const alb = new elbv2.ApplicationLoadBalancer(this, generateName('ALB'), {
      vpc,
      internetFacing: true,
    });

    const listener = alb.addListener('Listener', {
      open: true,
      certificates: [cert],
      protocol: elbv2.ApplicationProtocol.HTTPS,
    });

    // Connect ecsService to TargetGroup
    const targetGroup = listener.addTargets(generateName('LaravelTargetGroup'), {
      protocol: elbv2.ApplicationProtocol.HTTP,
      targets: [ecsService]
    });

    new cdk.CfnOutput(this, generateName('AlbDnsName'), {
      exportName: generateName('AlbDnsName'),
      value: alb.loadBalancerDnsName,
    });

    new cdk.CfnOutput(this, generateName('ActionCname'), {
      exportName: generateName('ActionCname'),
      value: 'Please setup a CNAME record mylaravel.' + deploymentEnv.domainName + ' to ' + alb.loadBalancerDnsName,
    });    

    new cdk.CfnOutput(this, generateName('ActionVisit'), {
      exportName: generateName('ActionVisit'),
      value: 'Visit https://mylaravel.' + deploymentEnv.domainName,
    });      

    //---------------------------------------------------------------------------
    // ecsService: Application Auto Scaling    
    const scaling = ecsService.autoScaleTaskCount({ 
      minCapacity: 2,
      maxCapacity: 10 
    });

    scaling.scaleOnCpuUtilization('CpuScaling', {
      targetUtilizationPercent: 50
    });
    
    scaling.scaleOnRequestCount('RequestScaling', {
      requestsPerTarget: 30,
      targetGroup: targetGroup
    });
  }
Example #7
Source File: Header.tsx    From frontend with Apache License 2.0 4 votes vote down vote up
Header = () => {
  const { t } = useTranslation();
  const router = useRouter()
  const [query, setQuery] = useState('')
  const [isMenuOpen, setMenuOpen] = useState(false)

  useEffect(() => {
    const q = router.query.query as string
    if (q) {
      setQuery(q)
    }
  }, [router.query.query])

  const mobileSize = 768
  const [isMobile, setIsMobile] = useState(true)

  useEffect(() => {
    window.addEventListener(
      'resize',
      () => {
        const ismobile = window.innerWidth < mobileSize
        if (ismobile !== isMobile) setIsMobile(ismobile)
      },
      false
    )

    return () => {
      window.removeEventListener('resize', () => { }, false)
    }
  }, [isMobile])

  const onChange = (e: ChangeEvent<HTMLInputElement>) => {
    e.preventDefault()
    setQuery(e.target.value)
  }

  const onSubmit = (e: ChangeEvent<HTMLFormElement>) => {
    e.preventDefault()
    if (query !== '') {
      router.push(`/apps/search/${query}`)
    }
  }

  const toggleMenu = () => {
    setMenuOpen(!isMenuOpen)
  }

  return (
    <header className={styles.header}>
      <nav className={styles.navHeader}>
        <span className={styles.brandContainer}>
          <LogoJsonLd
            logo={`${env.NEXT_PUBLIC_BASE_URL}/img/logo/flathub-logo-toolbar.svg`}
            url={`${env.NEXT_PUBLIC_BASE_URL}`}
          />
          <Link href='/' passHref>
            <a id={styles.brand} title={t('go-home')}></a>
          </Link>
        </span>

        <div id={styles.search}>
          <SiteLinksSearchBoxJsonLd
            url={process.env.NEXT_PUBLIC_SITE_BASE_URI}
            potentialActions={[
              {
                target: `${process.env.NEXT_PUBLIC_SITE_BASE_URI}/apps/search/{search_term_string}`,
                queryInput: 'search_term_string',
              },
            ]}
          />
          <form onSubmit={onSubmit}>
            <MdSearch className={styles.searchIcon} />
            <input
              type='search'
              name='q'
              placeholder={t('search-apps')}
              onChange={onChange}
              value={query}
              aria-label={t('search-apps')}
            />
          </form>
        </div>
        <span className={`${styles.navbarContainer}`}>
          <div
            id={styles.navbar}
            className={`${isMenuOpen && isMobile ? styles.responsive : ''}`}
          >

            <div className={styles.navItem}>
              <a
                href='https://github.com/flathub/flathub/wiki/App-Submission'
                target='_blank'
                rel='noreferrer'
              >
                {t('publish')}
              </a>
            </div>

            <div className={styles.navItem}>
              <a
                href='https://discourse.flathub.org/'
                target='_blank'
                rel='noreferrer'
              >
                {t('forum')}
              </a>
            </div>

            <Link href='/about' passHref>
              <a className={styles.navItem}>{t('about')}</a>
            </Link>
          </div>
          <div className={styles.toggleContainer}>
            <span className={`${styles.navbarToggle}`} onClick={toggleMenu}>
              {isMenuOpen && isMobile ? <MdMenuOpen /> : <MdMenu />}
            </span>
          </div>
        </span>
      </nav>
    </header>
  )
}