Skip to content
Merged
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
2 changes: 1 addition & 1 deletion libs/scully/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scullyio/scully",
"version": "0.0.96",
"version": "0.0.97",
"description": "Scully CLI",
"repository": {
"type": "GIT",
Expand Down
9 changes: 6 additions & 3 deletions libs/scully/src/lib/startBackgroundServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import {
handle404,
} from './utils/cli-options';
import { ScullyConfig } from './utils/interfacesandenums';
import { green, log, logError } from './utils/log';
import { green, log, logError, logWarn } from './utils/log';
import yargs from 'yargs';
import { handleTravesal } from '..';

const baseBinary = __dirname + '/scully.js';

Expand All @@ -37,8 +38,6 @@ export function startBackgroundServer(scullyConfig: ScullyConfig) {
tds ? 'true' : 'false',
'--pjf',
pjFirst ? 'true' : 'false',
'--404',
handle404,
];
if (configFileName) {
options.push('--cf');
Expand All @@ -47,6 +46,10 @@ export function startBackgroundServer(scullyConfig: ScullyConfig) {
options.push('--project');
options.push(scullyConfig.projectName);
}
if (handle404) {
options.push('--404');
options.push(handle404);
}
spawn(
'node',
options,
Expand Down
18 changes: 10 additions & 8 deletions libs/scully/src/lib/utils/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ export enum LogSeverity {
}

const logToFile = loadConfig
.then(() =>
createWriteStream(join(scullyConfig.homeFolder, 'scully.log'), {
flags: 'a', // 'a' means appending (old data will be preserved)
})
)
.then(() => (string) => {
return new Promise((res, rej) =>
appendFile(join(scullyConfig.homeFolder, 'scully.log'), string, (e) =>
e ? rej(e) : res
)
);
})
.then((file) => {
/** inject a couple of newlines to indicate new run */
file.write('\n\n\n');
file('\n\n\n');
return file;
});
export const log = (...a) => enhancedLog(white, LogSeverity.normal, ...a);
Expand All @@ -39,8 +41,8 @@ function enhancedLog(colorFn, severity: LogSeverity, ...args: any[]) {
logToFile
.then((file) => {
if (severity >= scullyConfig.logFileSeverity) {
file.write(out.join('\n'));
file.write('\n');
file(out.join('\n'));
file('\n');
}
})
.catch((e) => {
Expand Down
17 changes: 11 additions & 6 deletions libs/scully/src/lib/utils/serverstuff/handleUnknownRoute.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-case-declarations */
import { RequestHandler } from 'express';
import { readFileSync, statSync } from 'fs-extra';
import { join } from 'path';
Expand All @@ -18,17 +19,21 @@ export const handleUnknownRoute: RequestHandler = async (req, res, next) => {
const h404 = (handle404.trim() === '' ? scullyConfig.handle404 : handle404)
.trim()
.toLowerCase();
const scullyRoutes =
h404 === '' ? loadHandledRoutes() : await handleTravesal();
if (scullyRoutes.find(matchRoute(req))) {
/** this is a base route known by Scully, just return the index */
return res.sendFile(join(scullyConfig.outDir, '/index.html'));
}

switch (h404) {
case '':
const myHandledRoutes = loadHandledRoutes();
if (myHandledRoutes.includes(req.url)) {
return res.sendFile(join(scullyConfig.outDir, '/index.html'));
}
break;
case 'onlybase':
case 'baseonly':
const unhandledRoutes = await handleTravesal();
if (unhandledRoutes.find(matchRoute(req))) {
/** this is a base route known by Scully, just return the index */
return res.sendFile(join(scullyConfig.outDir, '/index.html'));
}
/** use fallthrough as all of those are served by the above route-machers, and only here if the route is 404 */
break;
case 'index':
Expand Down
2 changes: 2 additions & 0 deletions libs/scully/src/lib/utils/serverstuff/staticServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { addSSL } from './addSSL';
import { startDataServer } from './dataServer';
import { handleUnknownRoute } from './handleUnknownRoute';
import { proxyAdd } from './proxyAdd';
import { loadConfig } from '../config';

let angularServerInstance: { close: () => void };
let scullyServerInstance: { close: () => void };
Expand All @@ -19,6 +20,7 @@ let dataServerInstance: { close: () => void };
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export async function staticServer(port?: number) {
try {
await loadConfig;
port = port || scullyConfig.staticport;
const hostName = scullyConfig.hostName;
const scullyServer = express();
Expand Down