import * as http from "http" ; import * as https from "https" ; import AccountDataStore from "../common/AccountDataStore" ; import { CertOptions } from "../common/ConfigurationBase" ; import IAccountDataStore from "../common/IAccountDataStore" ; import IRequestListenerFactory from "../common/IRequestListenerFactory" ; import logger from "../common/Logger" ; import ITableMetadataStore from "../table/persistence/ITableMetadataStore" ; import LokiTableMetadataStore from "../table/persistence/LokiTableMetadataStore" ; import ServerBase from "../common/ServerBase" ; import TableConfiguration from "./TableConfiguration" ; import TableRequestListenerFactory from "./TableRequestListenerFactory" ; export class export default class TableServer extends ServerBase { private readonly metadataStore : ITableMetadataStore ; private readonly accountDataStore : IAccountDataStore ; constructor ( configuration ? ) { if ( configuration === undefined ) { configuration = new TableConfiguration ( ) ; } let httpServer ; const certOption = configuration . hasCert ( ) ; switch ( certOption ) { case CertOptions . PEM : case CertOptions . PFX : httpServer = https . createServer ( configuration . getCert ( certOption ) ! ) ; break ; default : httpServer = http . createServer ( ) ; } const metadataStore = new LokiTableMetadataStore ( configuration . metadataDBPath ) ; const accountDataStore = new AccountDataStore ( logger ) ; const requestListenerFactory = new TableRequestListenerFactory ( metadataStore , accountDataStore , configuration . enableAccessLog , configuration . accessLogWriteStream , configuration . skipApiVersionCheck , configuration . getOAuthLevel ( ) , configuration . disableProductStyleUrl ) ; const host = configuration . host ; const port = configuration . port ; super ( host , port , httpServer , requestListenerFactory , configuration ) ; this . metadataStore = metadataStore ; this . accountDataStore = accountDataStore ; } protected async beforeStart ( ) { const msg = `Azurite Table service is starting on ${ this . host }:${ this . port }` ; logger . info ( msg ) ; if ( this . accountDataStore !== undefined ) { await this . accountDataStore . init ( ) ; } if ( this . metadataStore !== undefined ) { await this . metadataStore . init ( ) ; } } protected async afterStart ( ) { const msg = `Azurite Table service successfully listens on ${ this . getHttpServerAddress ( ) }` ; logger . info ( msg ) ; } protected async beforeClose ( ) { const BEFORE_CLOSE_MESSAGE = `Azurite Table service is closing...` ; logger . info ( BEFORE_CLOSE_MESSAGE ) ; } protected async afterClose ( ) { if ( this . metadataStore !== undefined ) { await this . metadataStore . close ( ) ; } if ( this . accountDataStore !== undefined ) { await this . accountDataStore . close ( ) ; } const AFTER_CLOSE_MESSAGE = `Azurite Table service successfully closed` ; logger . info ( AFTER_CLOSE_MESSAGE ) ; } }