Skip to content

Commit

Permalink
Refactor for matching code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthv96 committed May 30, 2021
1 parent 4632240 commit 31e21f7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .changeset/soft-bikes-bake.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'@sveltejs/kit': patch
---

Fix issue with base path redirect.
Fix redirect URLs when removing/adding trailing slash when `base` path is set
24 changes: 12 additions & 12 deletions packages/kit/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ function handle_error(error) {
/**
* @param {number} port
* @param {boolean} https
* @param {string} basePath
* @param {string} base
*/
async function launch(port, https, basePath) {
async function launch(port, https, base) {
const { exec } = await import('child_process');
let cmd = 'open';
if (process.platform == 'win32') {
Expand All @@ -65,7 +65,7 @@ async function launch(port, https, basePath) {
cmd = 'xdg-open';
}
}
exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}${basePath}`);
exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}${base}`);
}

const prog = sade('svelte-kit').version('__VERSION__');
Expand All @@ -82,7 +82,7 @@ prog

process.env.NODE_ENV = 'development';
const config = await get_config();
const basePath = config.kit.paths.base;
const { base } = config.kit.paths;

const { dev } = await import('./core/dev/index.js');

Expand All @@ -97,7 +97,7 @@ prog
process.stderr.write(data);
});

welcome({ port, host, https, open, basePath });
welcome({ port, host, https, open, base });
} catch (error) {
handle_error(error);
}
Expand Down Expand Up @@ -150,13 +150,13 @@ prog

process.env.NODE_ENV = 'production';
const config = await get_config();
const basePath = config.kit.paths.base;
const { base } = config.kit.paths;
const { start } = await import('./core/start/index.js');

try {
await start({ port, host, config, https });

welcome({ port, host, https, open, basePath });
welcome({ port, host, https, open, base });
} catch (error) {
handle_error(error);
}
Expand Down Expand Up @@ -220,11 +220,11 @@ async function check_port(port) {
* host: string;
* https: boolean;
* port: number;
* basePath: string;
* base: string;
* }} param0
*/
function welcome({ port, host, https, open, basePath }) {
if (open) launch(port, https, basePath);
function welcome({ port, host, https, open, base }) {
if (open) launch(port, https, base);

console.log(colors.bold().cyan(`\n SvelteKit v${'__VERSION__'}\n`));

Expand All @@ -237,12 +237,12 @@ function welcome({ port, host, https, open, basePath }) {

// prettier-ignore
if (details.internal) {
console.log(` ${colors.gray('local: ')} ${protocol}//${colors.bold(`localhost:${port}${basePath}`)}`);
console.log(` ${colors.gray('local: ')} ${protocol}//${colors.bold(`localhost:${port}${base}`)}`);
} else {
if (details.mac === '00:00:00:00:00:00') return;

if (exposed) {
console.log(` ${colors.gray('network:')} ${protocol}//${colors.bold(`${details.address}:${port}${basePath}`)}`);
console.log(` ${colors.gray('network:')} ${protocol}//${colors.bold(`${details.address}:${port}${base}`)}`);
} else {
console.log(` ${colors.gray('network: not exposed')}`);
}
Expand Down
7 changes: 2 additions & 5 deletions packages/kit/test/apps/aa-routing/src/routes/valid/_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import * as assert from 'uvu/assert';

/** @type {import('test').TestMaker} */
export default function (test, is_dev) {
test('baspath is loaded', '/basePath/valid', async ({ page }) => {
assert.equal(
await page.innerHTML('h1'),
`Hello from the server in ${is_dev ? 'dev' : 'prod'} mode!`
);
test('basepath is loaded', '/basePath/valid', async ({ page }) => {
assert.equal(await page.innerHTML('h1'), 'Hello!');
});
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
<script>
import { browser, dev } from '$app/env';
</script>

<h1>Hello from the {browser ? 'client' : 'server'} in {dev ? 'dev' : 'prod'} mode!</h1>
<h1>Hello!</h1>

0 comments on commit 31e21f7

Please sign in to comment.