Skip to content

Commit

Permalink
pass port and hostname to local-access(?) and update console output
Browse files Browse the repository at this point in the history
  • Loading branch information
jperezlatimes committed Nov 22, 2024
1 parent cce952f commit b8417cd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
14 changes: 5 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import puppeteer from 'puppeteer';
// local
import { isProductionEnv, getBasePath } from './env.js';
import {
clearConsole,
onError,
printInstructions,
validAudioExtensions,
Expand Down Expand Up @@ -133,7 +132,7 @@ export class Baker extends EventEmitter {
// to prep for deploy, ensures there's a leading slash
this.pathPrefix = isProductionEnv ? resolve('/', pathPrefix) : '/';

this.port = port;
this.port = port || 3000;

// the root domain for the project, which will get pulled into select
// places for URL building
Expand Down Expand Up @@ -455,7 +454,7 @@ export class Baker extends EventEmitter {
// prep the server instance
const server = create({
dir: [this.output, this.input],
port: this.port,
port: this.port
});

// track the errors
Expand All @@ -465,8 +464,7 @@ export class Baker extends EventEmitter {
let dataError = null;
let assetsError = null;

clearConsole();
console.log(yellow('Starting initial serve...'));
console.log(yellow('Starting server...'));

let data;

Expand Down Expand Up @@ -503,11 +501,9 @@ export class Baker extends EventEmitter {
templatesError = err;
}

const { local, network: external, hostname } = await server.start();
await server.start();

const logStatus = () => {
clearConsole();

let hadError = false;

if (templatesError) {
Expand Down Expand Up @@ -537,7 +533,7 @@ export class Baker extends EventEmitter {

if (!hadError) {
console.log(green('Project compiled successfully!'));
printInstructions({ external, local, hostname });
printInstructions(this.port);
}
};

Expand Down
16 changes: 5 additions & 11 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,15 @@ export function clearConsole() {
}

/**
* @param {{ external: string, local: string, hostname: string}} config
* @param {number|string} port
*/
export function printInstructions({ external, local, hostname }) {
export function printInstructions(port) {
console.log('\nYou can now view your project in your browser\n');
console.log(`${bold('Server hostname:')} ${hostname}`)

if (local) {
console.log(`${bold('Local server URL:')} ${local}`);
}

if (external) {
console.log(`${bold('URL on your network:')} ${external}`);
}
console.log(`${bold('Local server is running on:')}`);

console.log();
console.log(` * http://localhost:${port}`);
console.log(` * http://127.0.0.1:${port}\n`);
}

export function logErrorMessage(err) {
Expand Down
9 changes: 5 additions & 4 deletions patches/mini-sync+0.3.0.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/node_modules/mini-sync/server.js b/node_modules/mini-sync/server.js
index 5a26905..63704a1 100644
index 5a26905..ee69282 100644
--- a/node_modules/mini-sync/server.js
+++ b/node_modules/mini-sync/server.js
@@ -61,6 +61,7 @@ const clientScript = fs.readFileSync(resolve(__dirname, pkg['umd:main']));
Expand All @@ -19,7 +19,7 @@ index 5a26905..63704a1 100644
// create a raw instance of http.Server so we can hook into it
const server = http.createServer();

@@ -190,20 +191,13 @@ function create({ dir = process.cwd(), port = 3000 } = {}) {
@@ -190,28 +191,21 @@ function create({ dir = process.cwd(), port = 3000 } = {}) {
* @returns {Promise<StartReturn>}
*/
function start() {
Expand All @@ -43,9 +43,10 @@ index 5a26905..63704a1 100644
server.on('listening', () => {
// ping every 10 seconds
interval = setInterval(sendPing, 10e3);
@@ -211,7 +205,7 @@ function create({ dir = process.cwd(), port = 3000 } = {}) {
// get paths to networks
const { local, network } = access({ port });
- const { local, network } = access({ port });
+ const { local, network } = access({ port, hostname });

- resolve({ local, network, port });
+ resolve({ local, network, port, hostname });
Expand Down

0 comments on commit b8417cd

Please sign in to comment.