Skip to content

Commit

Permalink
Add port cli config
Browse files Browse the repository at this point in the history
  • Loading branch information
jlpereira committed Apr 20, 2023
1 parent 138ebf2 commit d9cdae4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"eslint": "^8.38.0",
"eslint-plugin-vue": "^9.11.0",
"express": "^4.18.2",
"minimist": "^1.2.8",
"postcss": "^8.4.22",
"sass": "^1.62.0",
"tailwindcss": "^3.3.1",
Expand Down
19 changes: 9 additions & 10 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// @ts-check
import fs from 'node:fs'
import path from 'node:path'
import minimist from 'minimist'
import { fileURLToPath } from 'node:url'
import express from 'express'
import { generateConsoleMessage } from './src/ssr/utils/generateConsoleMessage.js'

const isTest = process.env.VITEST
const { port = 6173 } = minimist(process.argv.slice(2))

export async function createServer(
root = process.cwd(),
Expand Down Expand Up @@ -37,7 +38,7 @@ export async function createServer(
).createServer({
base: '/',
root,
logLevel: isTest ? 'error' : 'info',
logLevel: 'info',
server: {
middlewareMode: true,
watch: {
Expand Down Expand Up @@ -98,14 +99,12 @@ export async function createServer(
return { app, vite }
}

if (!isTest) {
createServer().then(({ app }) =>
app.listen(6173, () => {
generateConsoleMessage({ port: 6173, url: 'http://localhost' })
})
)
}

function makeAppContainer(app = '') {
return `<div id="app">${app}</div>`
}

createServer().then(({ app }) =>
app.listen(port, () => {
generateConsoleMessage({ port, url: 'http://localhost' })
})
)

0 comments on commit d9cdae4

Please sign in to comment.