diff --git a/projects/aas-lib/src/lib/auth/register-form/register-form.component.html b/projects/aas-lib/src/lib/auth/register-form/register-form.component.html
index 045a0528..dd59ab84 100644
--- a/projects/aas-lib/src/lib/auth/register-form/register-form.component.html
+++ b/projects/aas-lib/src/lib/auth/register-form/register-form.component.html
@@ -30,7 +30,7 @@
[placeholder]="defaultName()">
- @if (!passwordAsEMail) {
+ @if (!passwordAsEMail()) {
diff --git a/projects/aas-portal/src/app/start/add-endpoint-form/add-endpoint-form.component.ts b/projects/aas-portal/src/app/start/add-endpoint-form/add-endpoint-form.component.ts
index 36d854bb..f49fe1ab 100644
--- a/projects/aas-portal/src/app/start/add-endpoint-form/add-endpoint-form.component.ts
+++ b/projects/aas-portal/src/app/start/add-endpoint-form/add-endpoint-form.component.ts
@@ -82,13 +82,13 @@ export class AddEndpointFormComponent {
const name = this.validateName();
const url = this.validateUrl(this.item().value.trim());
if (name && url) {
- let version = url.searchParams.get('version');
+ const version = url.searchParams.get('version');
url.search = '';
const endpoint: AASEndpoint = { url: url.href, name, type: this.item().type };
if (version) {
endpoint.version = version;
} else if (this.item().type === 'AAS_API') {
- version = 'v3';
+ endpoint.version = 'v3';
}
this.modal.close(endpoint);
diff --git a/projects/aas-server/src/app/packages/server-message.ts b/projects/aas-server/src/app/packages/server-message.ts
index 1e10bf0b..b22f590c 100644
--- a/projects/aas-server/src/app/packages/server-message.ts
+++ b/projects/aas-server/src/app/packages/server-message.ts
@@ -7,6 +7,7 @@
*****************************************************************************/
import http from 'http';
+import https from 'https';
import net from 'net';
import FormData from 'form-data';
import { parseUrl } from '../convert.js';
@@ -19,6 +20,75 @@ export class ServerMessage {
* @returns The requested object.
*/
public get(url: URL): Promise {
+ return url.protocol === 'http:' ? this.getHttp(url) : this.getHttps(url);
+ }
+
+ /**
+ * Gets the response of the request with the specified URL.
+ * @param url The URL of the request.
+ * @returns The request.
+ */
+ public getResponse(url: URL): Promise {
+ return url.protocol === 'http:' ? this.getResponseHttp(url) : this.getResponseHttps(url);
+ }
+
+ /**
+ * Updates the specified object.
+ * @param url The destination URL.
+ * @param obj The object to send.
+ */
+ public put(url: URL, obj: object): Promise {
+ return url.protocol === 'http:' ? this.putHttp(url, obj) : this.putHttps(url, obj);
+ }
+
+ /**
+ * Inserts the specified object.
+ * @param url The destination URL.
+ * @param obj The object to send.
+ */
+ public post(url: URL, obj: FormData | object): Promise {
+ return obj instanceof FormData ? this.postFormData(url, obj) : this.postObject(url, obj);
+ }
+
+ /**
+ * Deletes an object.
+ * @param url The URL of the object to delete.
+ */
+ public delete(url: URL): Promise {
+ return url.protocol === 'http:' ? this.deleteHttp(url) : this.deleteHttps(url);
+ }
+
+ /**
+ * Checks the connection to resource with the specified URL.
+ * @param url The current URL.
+ */
+ public async checkUrlExist(url: string): Promise {
+ const temp = parseUrl(url);
+ const exist = await new Promise(resolve => {
+ const socket = net.createConnection(Number(temp.port), temp.hostname);
+ socket.setTimeout(3000);
+ socket.on('connect', () => {
+ socket.end();
+ resolve(true);
+ });
+
+ socket.on('timeout', () => {
+ socket.destroy();
+ resolve(false);
+ });
+
+ socket.on('error', () => {
+ socket.destroy();
+ resolve(false);
+ });
+ });
+
+ if (!exist) {
+ throw new Error(`${url} does not exist.`);
+ }
+ }
+
+ private getHttp(url: URL): Promise {
return new Promise((result, reject) => {
const options: http.RequestOptions = {
host: url.hostname,
@@ -53,12 +123,42 @@ export class ServerMessage {
});
}
- /**
- * Gets the response of the request with the specified URL.
- * @param url The URL of the request.
- * @returns The request.
- */
- public getResponse(url: URL): Promise {
+ private getHttps(url: URL): Promise {
+ return new Promise((result, reject) => {
+ const options: https.RequestOptions = {
+ host: url.hostname,
+ port: url.port,
+ path: url.pathname + url.search,
+ method: 'GET',
+ timeout: 3000,
+ };
+
+ const request = http.request(options, response => {
+ let data = '';
+ response.on('data', (chunk: string) => {
+ data += chunk;
+ });
+
+ response.on('end', () => {
+ try {
+ ServerMessage.checkStatusCode(response, data);
+ result(JSON.parse(data));
+ } catch (error) {
+ reject(error);
+ }
+ });
+
+ response.on('error', error => reject(error));
+ });
+
+ request
+ .on('timeout', () => request.destroy())
+ .on('error', error => reject(error))
+ .end();
+ });
+ }
+
+ private getResponseHttp(url: URL): Promise {
return new Promise((result, reject) => {
const options: http.RequestOptions = {
host: url.hostname,
@@ -76,12 +176,25 @@ export class ServerMessage {
});
}
- /**
- * Updates the specified object.
- * @param url The destination URL.
- * @param obj The object to send.
- */
- public put(url: URL, obj: object): Promise {
+ private getResponseHttps(url: URL): Promise {
+ return new Promise((result, reject) => {
+ const options: https.RequestOptions = {
+ host: url.hostname,
+ port: url.port,
+ path: url.pathname + url.search,
+ method: 'GET',
+ timeout: 3000,
+ };
+
+ const request = https.request(options, response => result(response));
+ request
+ .on('timeout', () => request.destroy())
+ .on('error', error => reject(error))
+ .end();
+ });
+ }
+
+ private putHttp(url: URL, obj: object): Promise {
return new Promise((result, reject) => {
const data = JSON.stringify(obj);
const options: http.RequestOptions = {
@@ -120,20 +233,128 @@ export class ServerMessage {
});
}
- /**
- * Inserts the specified object.
- * @param url The destination URL.
- * @param obj The object to send.
- */
- public post(url: URL, obj: FormData | object): Promise {
- return obj instanceof FormData ? this.postFormData(url, obj) : this.postObject(url, obj);
+ private putHttps(url: URL, obj: object): Promise {
+ return new Promise((result, reject) => {
+ const data = JSON.stringify(obj);
+ const options: https.RequestOptions = {
+ hostname: url.hostname,
+ port: url.port,
+ path: url.pathname + url.search,
+ method: 'PUT',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Content-Length': Buffer.byteLength(data),
+ },
+ };
+
+ const request = https
+ .request(options, response => {
+ let responseData = '';
+ response.on('data', (chunk: string) => {
+ responseData += chunk;
+ });
+
+ response.on('end', () => {
+ try {
+ ServerMessage.checkStatusCode(response, responseData);
+ result(responseData);
+ } catch (error) {
+ reject(error);
+ }
+ });
+
+ response.on('error', error => reject(error));
+ })
+ .on('error', error => reject(error));
+
+ request.write(data);
+ request.end();
+ });
}
- /**
- * Deletes an object.
- * @param url The URL of the object to delete.
- */
- public delete(url: URL): Promise {
+ private postObject(url: URL, obj: object): Promise {
+ return url.protocol === 'http:' ? this.postObjectHttp(url, obj) : this.postObjectHttps(url, obj);
+ }
+
+ private postObjectHttp(url: URL, obj: object): Promise {
+ return new Promise((result, reject) => {
+ const data = JSON.stringify(obj);
+ const options: http.RequestOptions = {
+ hostname: url.hostname,
+ port: url.port,
+ path: url.pathname + url.search,
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Content-Length': Buffer.byteLength(data),
+ },
+ };
+
+ const request = http
+ .request(options, response => {
+ let responseData = '';
+ response.on('data', (chunk: string) => {
+ responseData += chunk;
+ });
+
+ response.on('end', () => {
+ try {
+ ServerMessage.checkStatusCode(response, responseData);
+ result(responseData);
+ } catch (error) {
+ reject(error);
+ }
+ });
+
+ response.on('error', error => reject(error));
+ })
+ .on('error', error => reject(error));
+
+ request.write(data);
+ request.end();
+ });
+ }
+
+ private postObjectHttps(url: URL, obj: object): Promise {
+ return new Promise((result, reject) => {
+ const data = JSON.stringify(obj);
+ const options: https.RequestOptions = {
+ hostname: url.hostname,
+ port: url.port,
+ path: url.pathname + url.search,
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Content-Length': Buffer.byteLength(data),
+ },
+ };
+
+ const request = https
+ .request(options, response => {
+ let responseData = '';
+ response.on('data', (chunk: string) => {
+ responseData += chunk;
+ });
+
+ response.on('end', () => {
+ try {
+ ServerMessage.checkStatusCode(response, responseData);
+ result(responseData);
+ } catch (error) {
+ reject(error);
+ }
+ });
+
+ response.on('error', error => reject(error));
+ })
+ .on('error', error => reject(error));
+
+ request.write(data);
+ request.end();
+ });
+ }
+
+ private deleteHttp(url: URL): Promise {
return new Promise((result, reject) => {
const options: http.RequestOptions = {
hostname: url.hostname,
@@ -167,48 +388,53 @@ export class ServerMessage {
});
}
- /**
- * Checks the connection to resource with the specified URL.
- * @param url The current URL.
- */
- public async checkUrlExist(url: string): Promise {
- const temp = parseUrl(url);
- const exist = await new Promise(resolve => {
- const socket = net.createConnection(Number(temp.port), temp.hostname);
- socket.setTimeout(3000);
- socket.on('connect', () => {
- socket.end();
- resolve(true);
- });
+ private deleteHttps(url: URL): Promise {
+ return new Promise((result, reject) => {
+ const options: https.RequestOptions = {
+ hostname: url.hostname,
+ port: url.port,
+ path: url.pathname + url.search,
+ method: 'DELETE',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ };
- socket.on('timeout', () => {
- socket.destroy();
- resolve(false);
- });
+ https
+ .request(options, response => {
+ let responseData = '';
+ response.on('data', (chunk: string) => {
+ responseData += chunk;
+ });
- socket.on('error', () => {
- socket.destroy();
- resolve(false);
- });
+ response.on('end', function () {
+ try {
+ ServerMessage.checkStatusCode(response, responseData);
+ result(responseData);
+ } catch (error) {
+ reject(error);
+ }
+ });
+
+ response.on('error', error => reject(error));
+ })
+ .on('error', error => reject(error))
+ .end();
});
+ }
- if (!exist) {
- throw new Error(`${url} does not exist.`);
- }
+ private postFormData(url: URL, formData: FormData): Promise {
+ return url.protocol === 'http:' ? this.postFormDataHttp(url, formData) : this.postFormDataHttps(url, formData);
}
- private postObject(url: URL, obj: object): Promise {
+ private postFormDataHttp(url: URL, formData: FormData): Promise {
return new Promise((result, reject) => {
- const data = JSON.stringify(obj);
const options: http.RequestOptions = {
hostname: url.hostname,
port: url.port,
path: url.pathname + url.search,
method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Content-Length': Buffer.byteLength(data),
- },
+ headers: formData.getHeaders(),
};
const request = http
@@ -218,7 +444,7 @@ export class ServerMessage {
responseData += chunk;
});
- response.on('end', () => {
+ response.on('end', function () {
try {
ServerMessage.checkStatusCode(response, responseData);
result(responseData);
@@ -231,14 +457,13 @@ export class ServerMessage {
})
.on('error', error => reject(error));
- request.write(data);
- request.end();
+ formData.pipe(request);
});
}
- private postFormData(url: URL, formData: FormData): Promise {
+ private postFormDataHttps(url: URL, formData: FormData): Promise {
return new Promise((result, reject) => {
- const options: http.RequestOptions = {
+ const options: https.RequestOptions = {
hostname: url.hostname,
port: url.port,
path: url.pathname + url.search,
@@ -246,7 +471,7 @@ export class ServerMessage {
headers: formData.getHeaders(),
};
- const request = http
+ const request = https
.request(options, response => {
let responseData = '';
response.on('data', (chunk: string) => {