This repository has been archived by the owner on Jan 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
83 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { CommandBuilder } from 'yargs'; // eslint-disable-line | ||
import { join } from 'path'; | ||
import emojic from 'emojic'; | ||
import logger from '../../utils/logger'; | ||
|
||
import { server } from '../../index'; | ||
|
||
export const command = 'start [dir]'; | ||
export const aliases: string[] = ['s']; | ||
export const desc = 'start a production server'; | ||
|
||
export const builder: CommandBuilder = { | ||
log: { | ||
alias: 'l', | ||
description: 'enable or disable logs', | ||
boolean: true, | ||
default: true, | ||
}, | ||
port: { | ||
alias: 'p', | ||
description: 'specify which port the server should run on', | ||
}, | ||
dir: { | ||
default: './', | ||
description: 'base directory for the light server', | ||
hidden: true, | ||
}, | ||
}; | ||
|
||
interface Args { | ||
log: boolean; | ||
dir: string; | ||
port?: string; | ||
} | ||
|
||
const handle = async (argv: Args): Promise<void> => { | ||
logger.start(`${emojic.fire} igniting the server ${emojic.fire}`); | ||
|
||
const cwd = join(process.cwd(), argv.dir); | ||
const routesPath = join(cwd, './routes'); | ||
|
||
const app = server({ | ||
routes: routesPath, | ||
log: argv.log, | ||
}); | ||
|
||
interface ProcessEnv { | ||
[key: string]: string | number | undefined; | ||
} | ||
|
||
const { | ||
HOST = '0.0.0.0', | ||
}: ProcessEnv = process.env; | ||
|
||
let { | ||
PORT = 3000, | ||
}: ProcessEnv = process.env; | ||
if (argv.port) { | ||
PORT = argv.port; | ||
} | ||
|
||
app.server.listen(PORT, (HOST as any), (): void => { | ||
logger.listening(`on port ${PORT}`); | ||
}); | ||
}; | ||
|
||
export const handler = (argv: Args): void => { | ||
handle(argv).catch((err: Error): void => { | ||
logger.fatal(err); | ||
process.exit(1); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters