123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import { flags } from '@oclif/command'
- import { createApp } from '../services/webApi/app'
- import ApiCommandBase from '../command-base/ApiCommandBase'
- import logger from '../services/logger'
- export default class Server extends ApiCommandBase {
- static description = 'Starts the storage node server.'
- static flags = {
- worker: flags.integer({
- char: 'w',
- required: true,
- description: 'Storage provider worker ID',
- }),
- uploads: flags.string({
- char: 'd',
- required: true,
- description: 'Data uploading directory (absolute path).',
- }),
- port: flags.integer({
- char: 'o',
- required: true,
- description: 'Server port.',
- }),
- ...ApiCommandBase.flags,
- }
- static args = [{ name: 'file' }]
- async run(): Promise<void> {
- const { flags } = this.parse(Server)
- if (flags.dev) {
- await this.ensureDevelopmentChain()
- }
- const account = this.getAccount(flags)
- const api = await this.getApi()
- try {
- const port = flags.port
- const workerId = flags.worker ?? 0
- const app = await createApp(api, account, workerId, flags.uploads)
- logger.info(`Listening on http://localhost:${port}`)
- app.listen(port)
- } catch (err) {
- logger.error(`Error: ${err}`)
- }
- }
- // Override exiting.
- /* eslint-disable @typescript-eslint/no-empty-function */
- async finally(): Promise<void> {}
- }
|