Skip to content

Commit

Permalink
Don't use static file server for lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
Gideon Pyzer committed Aug 17, 2023
1 parent a76420f commit 016c31a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const createChromeAWSLambdaRenderer = () => async (event) => {
}
const target = createChromeAppTarget({
baseUrl: event.baseUrl,
useStaticServer: false,
});
try {
await target.start({
Expand Down
37 changes: 28 additions & 9 deletions packages/target-chrome-app/src/create-chrome-app-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ const {
} = require('@loki/core');
const { createChromeTarget } = require('@loki/target-chrome-core');

function createChromeAppTarget({
baseUrl = 'http://localhost:6006',
chromeFlags = ['--headless', '--disable-gpu', '--hide-scrollbars'],
}) {
let instance;
let staticServer;
function getStaticServerConfig(baseUrl) {
let staticServerPath;
let staticServerPort;

Expand All @@ -39,8 +34,27 @@ function createChromeAppTarget({
}
}

return {
chromeUrl,
isLocalFile,
staticServerPath,
staticServerPort,
};
}

function createChromeAppTarget({
baseUrl = 'http://localhost:6006',
useStaticServer = true,
chromeFlags = ['--headless', '--disable-gpu', '--hide-scrollbars'],
}) {
let instance;
let staticServer;

const { chromeUrl, isLocalFile, staticServerPath, staticServerPort } =
getStaticServerConfig(baseUrl);

async function start(options = {}) {
if (isLocalFile) {
if (useStaticServer && isLocalFile) {
staticServer = createStaticServer(staticServerPath);
staticServer.listen(staticServerPort);
debug(`Starting static file server at ${chromeUrl}`);
Expand All @@ -66,7 +80,7 @@ function createChromeAppTarget({
debug('No chrome instance to kill');
}

if (staticServer) {
if (useStaticServer && staticServer) {
staticServer.close();
}
}
Expand All @@ -86,7 +100,12 @@ function createChromeAppTarget({
return client;
}

return createChromeTarget(start, stop, createNewDebuggerInstance, chromeUrl);
return createChromeTarget(
start,
stop,
createNewDebuggerInstance,
useStaticServer ? chromeUrl : baseUrl
);
}

module.exports = createChromeAppTarget;

0 comments on commit 016c31a

Please sign in to comment.