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

🚦 set CONTENT_CDN_HOST in env of development server #1043

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions .changeset/sharp-wasps-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-cli': patch
---

Set `CONTENT_CDN_HOST` when `HOST` environment variable is specified and default to `localhost` otherwise. Also improve log messages when `HOST` is provided.
6 changes: 5 additions & 1 deletion packages/myst-cli/src/build/site/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ export function createServerLogger(session: ISession, ready: () => void): Logger
if (line.includes('File changed: app/content')) return; // This is shown elsewhere
if (line.includes('started at http://')) {
const [, ipAndPort] = line.split('http://');
const host =
process.env.HOST && process.env.HOST.startsWith('http')
? new URL(process.env.HOST).hostname
: process.env.HOST ?? 'localhost';
const port = ipAndPort.split(':')[1].replace(/[^0-9]/g, '');
const local = `http://localhost:${port}`;
const local = `http://${host}:${port}`;
ready();
session.log.info(
`\n🔌 Server started on port ${port}! 🥳 🎉\n\n\n\t👉 ${chalk.green(local)} 👈\n\n`,
Expand Down
3 changes: 2 additions & 1 deletion packages/myst-cli/src/build/site/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export async function startServer(
});
}
if (opts.headless) {
const local = chalk.green(`http://localhost:${server.port}`);
const local = chalk.green(`http://${process.env.HOST ?? 'localhost'}:${server.port}`);
session.log.info(
`\n🔌 Content server started on port ${server.port}! 🥳 🎉\n\n\n\t👉 ${local} 👈\n\n`,
);
Expand All @@ -142,6 +142,7 @@ export async function startServer(
cwd: mystTemplate.templatePath,
env: {
...process.env,
CONTENT_CDN_HOST: process.env.HOST ?? 'localhost',
CONTENT_CDN_PORT: String(server.port),
PORT: String(port),
MODE: opts.buildStatic ? 'static' : 'app',
Expand Down
Loading