Skip to content

Commit

Permalink
fix(hosturl): fix hostURL so the our internal server is not started, …
Browse files Browse the repository at this point in the history
…and we are quireing (#277)

dont start the internal server, and use the given one from `hostUrl`
  • Loading branch information
SanderElias committed Feb 5, 2020
1 parent 75543eb commit 88a1b26
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 22 deletions.
2 changes: 2 additions & 0 deletions README.md
@@ -1,5 +1,7 @@
# Scully

[![](./assets/logos/PNG/scullyio-logo.png)]()

[![GitHub](https://img.shields.io/github/license/scullyio/scully)](https://github.com/scullyio/scully/blob/master/LICENSE)
[![Gitter](https://img.shields.io/gitter/room/scullyio/community)](https://gitter.im/scullyio/community)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
Expand Down
1 change: 1 addition & 0 deletions scully.sampleBlog.config.js
Expand Up @@ -7,6 +7,7 @@ exports.config = {
/** outDir is where the static distribution files end up */
outDir: './dist/static',
// hostName: '0.0.0.0',
hostUrl: 'http://localHost:5000',
extraRoutes: [''],
routes: {
'/demo/:id': {
Expand Down
4 changes: 2 additions & 2 deletions scully/routerPlugins/traverseAppRoutesPlugin.ts
Expand Up @@ -42,9 +42,9 @@ ${green('When there are extraRoutes in your config, we will still try to render
}
// process.exit(15);
const allRoutes = [...routes, ...extraRoutes];
if (allRoutes.findIndex(r => r === '') === -1) {
if (allRoutes.findIndex(r => r.trim() === '' || r.trim() === '/') === -1) {
/** make sure the root Route is always rendered. */
allRoutes.push('');
allRoutes.push('/');
}
return allRoutes;
};
Expand Down
35 changes: 20 additions & 15 deletions scully/scully.ts
Expand Up @@ -8,11 +8,11 @@ import {join} from 'path';
import * as yargs from 'yargs';
import './pluginManagement/systemPlugins';
import {startBackgroundServer} from './startBackgroundServer';
import {loadConfig, scullyConfig} from './utils/config';
import {loadConfig} from './utils/config';
import {moveDistAngular} from './utils/fsAngular';
import {httpGetJson} from './utils/httpGetJson';
import {isPortTaken} from './utils/isPortTaken';
import {logError} from './utils/log';
import {logError, logWarn, yellow} from './utils/log';
import {startScully} from './utils/startup';
import {waitForServerToBeAvailable} from './utils/waitForServerToBeAvailable';
import {bootServe, isBuildThere, watchMode} from './watchMode';
Expand Down Expand Up @@ -62,29 +62,34 @@ if (process.argv.includes('version')) {
const folder = join(scullyConfig.homeFolder, scullyConfig.distFolder);
/** copy in current build artifacts */
await moveDistAngular(folder, scullyConfig.outDir, {removeStaticDist, reset: false});

/** server ports already in use? */
const isTaken = await isPortTaken(scullyConfig.staticport);
if (!isTaken) {
startBackgroundServer(scullyConfig);
} else {
// debug only
console.log(`Background servers already running.`);
}

if (!(await waitForServerToBeAvailable().catch(e => false))) {
logError('Could not connect to server');
process.exit(15);
if (typeof scullyConfig.hostUrl === 'string') {
logWarn(`
You are using "${yellow(scullyConfig.hostUrl)}" as server.
`);
} else {
/** server ports already in use? */
if (!isTaken) {
startBackgroundServer(scullyConfig);
} else {
// debug only
console.log(`Background servers already running.`);
}
if (!(await waitForServerToBeAvailable().catch(e => false))) {
logError('Could not connect to server');
process.exit(15);
}
}
if (watch) {
watchMode(
join(scullyConfig.homeFolder, scullyConfig.distFolder) ||
join(scullyConfig.homeFolder, './dist/browser')
);
} else {
console.log('servers available');
// console.log('servers available');
await startScully();
if (!isTaken) {
if (!isTaken && typeof scullyConfig.hostUrl !== 'string') {
// kill serve ports
await httpGetJson(`http://${scullyConfig.hostName}:${scullyConfig.appPort}/killMe`, {
suppressErrors: true,
Expand Down
2 changes: 2 additions & 0 deletions scully/utils/cache.ts
@@ -0,0 +1,2 @@
export const rawRoutesCache = new Set<string>();
export const flushRawRoutesCache = () => rawRoutesCache.clear();
9 changes: 4 additions & 5 deletions scully/utils/defaultAction.ts
Expand Up @@ -12,29 +12,28 @@ import {chunk} from './chunk';
import {loadConfig} from './config';
import {log, logWarn} from './log';
import {performanceIds} from './performanceIds';
import {rawRoutesCache} from './cache';

export const {baseFilter} = yargs
.string('bf')
.alias('bf', 'baseFilter')
.default('bf', '')
.describe('bf', 'provide a minimatch glob for the unhandled routes').argv;

const cache = new Set<string>();

console.log(baseFilter);
export const generateAll = async (localBaseFilter = baseFilter) => {
await loadConfig;
try {
let unhandledRoutes;
if (cache.size == 0) {
if (rawRoutesCache.size === 0) {
log('Finding all routes in application.');
performance.mark('startTraverse');
unhandledRoutes = await traverseAppRoutes();
performance.mark('stopTraverse');
performanceIds.add('Traverse');
unhandledRoutes.forEach(r => cache.add(r));
unhandledRoutes.forEach(r => rawRoutesCache.add(r));
} else {
unhandledRoutes = [...cache.keys()];
unhandledRoutes = [...rawRoutesCache.keys()];
}

if (unhandledRoutes.length < 1) {
Expand Down

0 comments on commit 88a1b26

Please sign in to comment.