Skip to content

Commit

Permalink
feat(packages/sui-ssr): add ssr dev support
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrés Alvarez authored and Andrés Alvarez committed Dec 13, 2023
1 parent bb2db70 commit 219685c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 24 deletions.
57 changes: 36 additions & 21 deletions packages/sui-ssr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,40 @@ SSR can be tought to configure and maintain. SSR handles that for you providing:
npm install @s-ui/ssr --save
```

## Development

Starts a development server.

```
Usage: sui-ssr-dev [options]
Options:
-L, --link-all [monorepo] Link all packages inside of monorepo multipackage
-l, --link-package [package] Replace each occurrence of this package with an absolute path to this folder (default: [])
-h, --help display help for command
Examples:
$ sui-ssr dev
$ sui-ssr dev --link-package ./domain --link-all ./components
```

## Build

Generate a static version of the server w/out dependencies in the server folder.

```
Usage: sui-ssr-build [options]
Options:
Usage: sui-ssr-build [options]
-C, --clean Remove build folder before create a new one
-V, --verbose Verbose output
-h, --help output usage information
Description:
Options:
Build a production ready ssr server
-C, --clean Remove build folder before create a new one
-V, --verbose Verbose output
-h, --help output usage information
Examples:
Examples:
$ sui-ssr build
$ sui-ssr build
```

## Archive
Expand All @@ -41,21 +56,21 @@ Create a zip file with all assets needed to run the server in any infra.
It will, over parameter, make that the express server run over a username and password in a htpasswd way.

```
Usage: sui-ssr-archive [options]
Usage: sui-ssr-archive [options]
Options:
Options:
-C, --clean Remove previous zip
-R, --docker-registry <dockerRegistry> Custom registry to be used as a proxy or instead of the Docker Hub registry
-E, --entry-point Relative path to an entry point script to replace the current one -> https://bit.ly/3e4wT8C
-h, --help Output usage information
-A, --auth <username:password> Will build the express definition under authentication htpassword like.
-O, --outputFileName <outputFileName> A string that will be used to set the name of the output filename. Keep in mind that the outputFilename will have the next suffix <outputFileName>-sui-ssr.zip
-C, --clean Remove previous zip
-R, --docker-registry <dockerRegistry> Custom registry to be used as a proxy or instead of the Docker Hub registry
-E, --entry-point Relative path to an entry point script to replace the current one -> https://bit.ly/3e4wT8C
-h, --help Output usage information
-A, --auth <username:password> Will build the express definition under authentication htpassword like.
-O, --outputFileName <outputFileName> A string that will be used to set the name of the output filename. Keep in mind that the outputFilename will have the next suffix <outputFileName>-sui-ssr.zip
Examples:
Examples:
$ sui-ssr archive
$ sui-ssr archive --outputFileName=myFile // output: myFile-sui-ssr.zip
$ sui-ssr archive
$ sui-ssr archive --outputFileName=myFile // output: myFile-sui-ssr.zip
```

### IMPORTANT!!
Expand Down
1 change: 1 addition & 0 deletions packages/sui-ssr/bin/sui-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ program.version(version, ' --version')
program.command('build', 'Build a ssr server').alias('b')
program.command('archive', 'Create a server.zip file').alias('a')
program.command('release', 'Release new version of the server').alias('r')
program.command('dev', 'Start a ssr server in development mode').alias('d')

program.parse(process.argv)
13 changes: 10 additions & 3 deletions packages/sui-ssr/server/utils/factory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const IS_PRODUCTION = process.env.NODE_ENV === 'production'
const DEFAULT_SITE_HEADER = 'X-Serve-Site'
const DEFAULT_PUBLIC_FOLDER = IS_PRODUCTION ? 'public' : '.sui/public'
const DEFAULT_PUBLIC_FOLDER = 'public'
const DEFAULT_DEV_PUBLIC_FOLDER = '.sui/public'
const DEFAULT_MULTI_SITE_KEY = 'default'
const EXPRESS_STATIC_CONFIG = {index: false}

Expand Down Expand Up @@ -29,8 +29,15 @@ export default ({path, fs, config: ssrConf = {}, assetsManifest}) => {
}

const publicFolder = req => {
if (process.env.NODE_ENV !== 'production') {
return DEFAULT_DEV_PUBLIC_FOLDER
}

const site = siteByHost(req)
if (!site || !IS_PRODUCTION) return DEFAULT_PUBLIC_FOLDER

if (!site) {
return DEFAULT_PUBLIC_FOLDER
}

return multiSitePublicFolder(site)
}
Expand Down

0 comments on commit 219685c

Please sign in to comment.