Skip to content

Commit

Permalink
fix: set correct app_location for static sites
Browse files Browse the repository at this point in the history
  • Loading branch information
manekinekko committed Sep 15, 2020
1 parent bcda33c commit ce4521d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/runtimeHost.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ module.exports.createRuntimeHost = (port, proxyHost, proxyPort) => {
const runtimeType = detectRuntime(app_location);

switch (runtimeType) {
// .NET runtime
case RuntimeType.dotnet:
return {
command: "dotnet",
args: `watch --project ${app_location} run --urls=http://localhost:${port}`.split(" "),
};

// Node.js runtime or static sites
case RuntimeType.node:
case RuntimeType.unknown:
default:

// See available options for http-server: https://github.com/http-party/http-server#available-options
// Note: --proxy allows us to add fallback routes for SPA (https://github.com/http-party/http-server#catch-all-redirect)
const command = httpServerBin;
Expand Down
7 changes: 7 additions & 0 deletions src/runtimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ const RuntimeType = {
module.exports.RuntimeType = RuntimeType;

module.exports.detectRuntime = (app_location) => {

if (fs.existsSync(app_location) === false) {
console.error(`The provided "app_location" was not found. Can't detect runtime!`);
console.error(app_location);
return RuntimeType.unknown;
}

const files = fs.readdirSync(app_location);

if (files.some((file) => path.extname(file) === ".csproj")) {
Expand Down
30 changes: 21 additions & 9 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,37 @@ module.exports.readConfigFile = () => {
const swaBuildConfig = swaYaml.jobs.build_and_deploy_job.steps.find((step) => step.uses && step.uses.includes("static-web-apps-deploy"));

// extract the user's config and set defaults
const {
let {
app_build_command = "npm run build --if-present",
api_build_command = "npm run build --if-present",
app_location = "/",
app_artifact_location = "/",
api_location = "api",
} = swaBuildConfig.with;


// the following locations must be under the user's project folder
// - app_location
// - api_location
// - app_artifact_location


app_location = path.join(process.cwd(), app_location);
api_location = path.join(process.cwd(), api_location);

const detectedRuntimeType = detectRuntime(app_location);
if (detectedRuntimeType === RuntimeType.node) {
app_artifact_location = path.join(app_location, "bin", "Debug", "netstandard2.1", "publish", app_artifact_location);
} else {
app_artifact_location = path.join(app_location, app_artifact_location);
}

const config = {
app_build_command,
api_build_command,

// these locations must be under the user's project folder
app_location: path.join(process.cwd(), app_location),
api_location: path.join(process.cwd(), api_location),
app_artifact_location:
detectRuntime(path.join(process.cwd(), app_location)) === RuntimeType.node
? path.join(process.cwd(), app_location, app_artifact_location)
: path.join(process.cwd(), app_location, "bin", "Debug", "netstandard2.1", "publish", app_artifact_location),
app_location,
api_location,
app_artifact_location,
};

return config;
Expand Down

0 comments on commit ce4521d

Please sign in to comment.