Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Commit 9bc90c4

Browse files
Merge pull request #24 from NativeScript/milanov/move-static-login-page-to-cloud
Move the login complete page in the server
2 parents e9f1652 + b05ea87 commit 9bc90c4

File tree

5 files changed

+26
-83
lines changed

5 files changed

+26
-83
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const tns = require("nativescript");
99

1010
### Module cloudBuildService
1111
The `cloudBuildService` allows build of applications in the cloud. You can call the following methods:
12-
* `build` method - it validates passed arguments and tries to build the application in the cloud. In case of successful build, the build result (.apk, .ipa or .zip) is downloaded. The result contains information about the whole build process, path to the downloaded build result and information used to generate a QR code, pointing to the latest build result (in S3). </br>
12+
* `build` method - it validates passed arguments and tries to build the application in the cloud. In case of successful build, the build result (.apk, .ipa or .zip) is downloaded. The result contains information about the whole build process, path to the downloaded build result and information used to generate a QR code, pointing to the latest build result (in S3). During the build the cloudBuildService will emit buildOutput event which will contain parts of the current build output.</br>
1313
Definition:
1414

1515
```TypeScript
@@ -51,6 +51,17 @@ const androidReleaseConfigurationData = {
5151
const platform = "android";
5252
const buildConfiguration = "release";
5353

54+
tns.cloudBuildService.on("buildOutput", (data) => {
55+
console.log(data);
56+
/*
57+
Sample data object:
58+
{
59+
"pipe": "stdout",
60+
"data": "Add platform ios with runtime version 2.5.*"
61+
}
62+
*/
63+
});
64+
5465
tns.cloudBuildService
5566
.build(projectSettings, platform, buildConfiguration, androidReleaseConfigurationData)
5667
.then(buildResult => console.log(buildResult))

lib/constants.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const BUILD_SERVICE_NAME = "build";
2424
export const EMULATORS_SERVICE_NAME = "emulators";
2525

2626
export const CLOUD_BUILD_EVENT_NAMES = {
27-
OUTPUT: "output"
27+
BUILD_OUTPUT: "buildOutput"
2828
};
2929

3030
export const DEVICE_DISCOVERY_EVENTS = {
@@ -58,11 +58,13 @@ export const HTTP_HEADERS = {
5858
ACCEPT: "Accept",
5959
AUTHORIZATION: "Authorization",
6060
CONNECTION: "Connection",
61-
CONTENT_TYPE: "Content-Type"
61+
CONTENT_TYPE: "Content-Type",
62+
LOCATION: "Location"
6263
};
6364

6465
export const HTTP_STATUS_CODES = {
6566
SUCCESS: 200,
67+
FOUND: 302,
6668
UNAUTHORIZED: 401,
6769
PAYMENT_REQUIRED: 402
6870
};

lib/services/authentication-service.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ServerRequest, ServerResponse, Server } from "http";
22
import { parse } from "url";
3-
import { join } from "path";
43
import { isInteractive } from "../helpers";
4+
import { HTTP_HEADERS, HTTP_STATUS_CODES } from "../constants";
55

66
export class AuthenticationService implements IAuthenticationService {
77
private static DEFAULT_NONINTERACTIVE_LOGIN_TIMEOUT_MS: number = 15 * 60 * 1000;
@@ -32,19 +32,21 @@ export class AuthenticationService implements IAuthenticationService {
3232
let loginUrl: string;
3333
this.localhostServer = this.$httpServer.createServer({
3434
routes: {
35-
"/": async (request: ServerRequest, response: ServerResponse) => {
35+
"/": (request: ServerRequest, response: ServerResponse) => {
3636
this.$logger.debug("Login complete: " + request.url);
3737
const parsedUrl = parse(request.url, true);
3838
const loginResponse = parsedUrl.query.response;
3939
if (loginResponse) {
40-
await this.serveLoginFile("end.html")(request, response);
40+
response.statusCode = HTTP_STATUS_CODES.FOUND;
41+
response.setHeader(HTTP_HEADERS.LOCATION, parsedUrl.query.loginCompleteUrl);
4142
this.killLocalhostServer();
4243

4344
isResolved = true;
4445

4546
const decodedResponse = new Buffer(loginResponse, "base64").toString();
4647
this.rejectLoginPromiseAction = null;
4748
authCompleteResolveAction(decodedResponse);
49+
response.end();
4850
} else {
4951
this.$httpServer.redirect(response, loginUrl);
5052
}
@@ -172,10 +174,6 @@ export class AuthenticationService implements IAuthenticationService {
172174
return tokenState;
173175
}
174176

175-
private serveLoginFile(relPath: string): (request: ServerRequest, response: ServerResponse) => Promise<void> {
176-
return this.$httpServer.serveFile(join(__dirname, "..", "..", "resources", "login", relPath));
177-
}
178-
179177
private killLocalhostServer(): void {
180178
this.localhostServer.close();
181179
this.localhostServer = null;

lib/services/cloud-build-service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ export class CloudBuildService extends EventEmitter implements ICloudBuildServic
7474
url: buildResultUrl
7575
};
7676

77+
const fullOutput = await this.getContentOfS3File(buildResponse.outputUrl);
78+
7779
const result = {
7880
stderr: buildResult.stderr,
7981
stdout: buildResult.stdout,
80-
fullOutput: buildResult.stdout,
82+
fullOutput: fullOutput,
8183
outputFilePath: localBuildResult,
8284
qrData: {
8385
originalUrl: buildResultUrl,
@@ -221,7 +223,8 @@ export class CloudBuildService extends EventEmitter implements ICloudBuildServic
221223
// The logs variable will contain the full build log and we need to log only the logs that we don't have.
222224
const contentToLog = this.$cloudBuildOutputFilter.filter(logs.substr(outputCursorPosition));
223225
if (contentToLog) {
224-
this.emit(constants.CLOUD_BUILD_EVENT_NAMES.OUTPUT, contentToLog);
226+
const data = { data: contentToLog, pipe: "stdout" };
227+
this.emit(constants.CLOUD_BUILD_EVENT_NAMES.BUILD_OUTPUT, data);
225228
this.$logger.info(contentToLog);
226229
}
227230

resources/login/end.html

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)