@@ -5,38 +5,38 @@ import path from 'path'
5
5
import chalk from 'chalk'
6
6
import { config } from 'dotenv-defaults'
7
7
import Fastify from 'fastify'
8
- import yargsParser from 'yargs-parser'
8
+ import { hideBin } from 'yargs/helpers'
9
+ import yargs from 'yargs/yargs'
9
10
10
11
import { getPaths , getConfig } from '@redwoodjs/project-config'
11
12
12
13
import { redwoodFastifyWeb } from './web'
13
14
import { withApiProxy } from './withApiProxy'
14
15
15
- interface Opts {
16
- socket ? : string
17
- port ? : string
18
- apiHost ? : string
19
- }
20
-
21
- // no help option...
22
-
23
16
async function serve ( ) {
24
- // Parse server file args
25
- const args = yargsParser ( process . argv . slice ( 2 ) , {
26
- string : [ 'port' , 'socket' , 'apiHost' ] ,
27
- alias : { apiHost : [ 'api-host' ] , port : [ 'p' ] } ,
28
- } )
29
-
30
- const options : Opts = {
31
- socket : args . socket ,
32
- port : args . port ,
33
- apiHost : args . apiHost ,
34
- }
17
+ const options = yargs ( hideBin ( process . argv ) )
18
+ . scriptName ( 'rw-web-server' )
19
+ . usage ( '$0' , 'Start server for serving only the web side' )
20
+ . strict ( )
21
+
22
+ . options ( {
23
+ port : {
24
+ default : getConfig ( ) . web ?. port || 8910 ,
25
+ type : 'number' ,
26
+ alias : 'p' ,
27
+ } ,
28
+ socket : { type : 'string' } ,
29
+ apiHost : {
30
+ alias : 'api-host' ,
31
+ type : 'string' ,
32
+ desc : 'Forward requests from the apiUrl, defined in redwood.toml to this host' ,
33
+ } ,
34
+ } )
35
+ . parseSync ( )
35
36
36
37
const redwoodProjectPaths = getPaths ( )
37
38
const redwoodConfig = getConfig ( )
38
39
39
- const port = options . port ? parseInt ( options . port ) : redwoodConfig . web . port
40
40
const apiUrl = redwoodConfig . web . apiUrl
41
41
42
42
const tsServer = Date . now ( )
@@ -84,7 +84,7 @@ async function serve() {
84
84
listenOptions = { path : options . socket }
85
85
} else {
86
86
listenOptions = {
87
- port,
87
+ port : options . port ,
88
88
host : process . env . NODE_ENV === 'production' ? '0.0.0.0' : '::' ,
89
89
}
90
90
}
@@ -95,7 +95,7 @@ async function serve() {
95
95
if ( options . socket ) {
96
96
console . log ( `Web server started on ${ options . socket } ` )
97
97
} else {
98
- console . log ( `Web server started on http://localhost:${ port } ` )
98
+ console . log ( `Web server started on http://localhost:${ options . port } ` )
99
99
}
100
100
} )
101
101
0 commit comments