Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added port option #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ module.exports = {
}
```

### Port

If none is specified the server uses a random available port.

Example:

```js
module.exports = {
port: 8080,
}
```

## CLI options

Run `presite --help`.
Expand Down
4 changes: 3 additions & 1 deletion src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import serveStatic from 'serve-static'
import { SPECIAL_EXTENSIONS_RE } from './Crawler'

type ServerOptions = {
port: number
baseDir: string
outDir: string
}
Expand Down Expand Up @@ -60,7 +61,8 @@ export class Server {
}

async start(): Promise<void> {
const port = await getPort()
const optsPort = this.opts.port
const port = optsPort !== undefined ? optsPort : await getPort()
this.port = port
this.server = new HttpServer(this.app.handler as any)
this.server.listen(this.port!, this.hostname)
Expand Down
3 changes: 3 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ async function main() {

cli
.command('[dir]', `Prerender your website`)
.option('-p, --port', 'Server port')
.option(
'--wait <time_or_selector>',
'Wait for specific ms or dom element to appear'
Expand All @@ -34,6 +35,7 @@ async function main() {
const { Logger } = await import('./Logger')

type ConfigInput = {
port?: number
baseDir?: string
outDir?: string
routes?: string[] | (() => Promise<string[]>)
Expand Down Expand Up @@ -72,6 +74,7 @@ async function main() {
const logger = new Logger({ verbose: !flags.quiet })

const server = new Server({
port: config.port,
baseDir: config.baseDir,
outDir: config.outDir,
})
Expand Down