1.0.64 • Published 3 years ago

@handstudio/hce-component-utils v1.0.64

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

hce-component-utils

현대건설기계의 어드민 웹 어플리케이션 및 프론트 웹 어플리케이션에서 공통으로 사용하는 기능들에 대한 라이브러리 입니다.

How to Install

npm install @handstudio/hce-component-utils

FileUploader module

파일 업로드 미들웨어를 만들어 반환합니다.

How to use (with parameters)

import { initUploader, getUploader } from '@handstudio/hce-component-utils';

(async () => {
  await initUploader({
    name: 'default',
      // Optional, 넘기지 않는 경우 기본값은 default

    type: 'FILE', 
      // 'FILE' | 'BYPASS'
      // 'FILE' -> use local file storage
      // 'BYPASS' -> use another web server

    // case of 'FILE'
    file: {
      storagePath: '/home/ec2-user/upload-files',
        // directory which the uploaded file saved
      selfBaseUrl: 'https://hce-dev.devhand.net'
        // uploaded URL public baseURL
    },

    // case of 'BYPASS'
    bypass: {
      bypassUrl: 'http://10.0.23.1:4000/api/upload', 
        // upload API Endpoint URL
    }
  });

  // register UploadHandler like this:
  app.post('/upload-api', getUploader());

  // or, register named UploaderHandler like this:
  app.post('/uplaod-api-another', getUploader('bypass'));
})();

How to use (with environment variables)

직접 코드로 Uploader관련 Configuration을 넣지 않고, 환경변수를 통해 Uploader를 초기화 할 수 있습니다. 사용되는 환경변수는 다음과 같습니다.

# 업로더 구현체 종류
UPLOADER=BYPASS|FILE # 각각 업로드 API Bypass, 직접 파일 저장을 의미

# BYPASS인 경우 필수 옵션들
UPLOADER_BYPASS_URL=http://10.0.201.2:4000/api/upload # 업로드 API URL

# FILE인 경우 필수 옵션들
UPLOADER_FILE_STORAGE_PATH=/ec2-user/uploaded-files # 파일시스템 path
UPLOADER_SELF_BASE_URL=https://hce-dev.devhand.net # 업로드된 파일의 Public Endpoint의 BaseURL

해당 환경변수를 공급한 후, 다음과 같이 초기화하고 사용합니다.

import { initUploader, getUploader } from '@handstudio/hce-component-utils';

(async () => {
  await initUploader();

  // register UploadHandler like this:
  app.post('/upload-api', getUploader());
})();

MailSender

메일 발송 모듈입니다.

메일 발송 function을 리턴합니다.

How to use (with parameters)

import { initMailSender, getMailSender } from '../lib/mailsender';

(async () => {
  initMailSender({
    serviceType: 'GMAIL',
    // GMAIL, SMTP
    gmailPassword: 'example',
    gmailUser: 'example@gmail.com',
    name: 'gmail'
  });

  const mailSender = getMailSender('gmail');
  mailSender({
    from: 'dlrmsgks12@gmail.com',
    to: 'buki@mhand.net',
    subject: '현대건설기계 테스트 메일입니다.',
    text: '현대건설기계 테스트 메일입니다.'
  });
})();

How to use (with environment variables)

메일 발송 모듈을 위한 값은 환경 변수로도 setting 할 수 있습니다.

# 메일 서비스 타입 GMAIL | SMTP
MAIL_SERVICE_TYPE=GMAIL 

# 지메일 사용 시 user
GMAIL_USER=example@gmail.com
# 지메일 사용 시 password
GMAIL_PASSWORD=example

# SMTP 사용 시 host 
SMTP_HOST=todo
# SMTP 사용 시 port
SMTP_PORT=todo
# SMTP 사용 시 user
SMTP_USER=todo
# SMTP 사용 시 password
SMTP_PASSWORD=todo

이메일 템플릿

사용시 환경변수 BASEURL가 필요합니다. 이메일