Skip to content

Commit 8e478dd

Browse files
committed
Comment out (temporarily) worker export to resolve CORS issues
1 parent 359d86b commit 8e478dd

File tree

3 files changed

+119
-1
lines changed

3 files changed

+119
-1
lines changed

src/FEAWorkerScript.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1+
// ______ ______ _____ _ _ //
2+
// | ____| ____| /\ / ____| (_) | | //
3+
// | |__ | |__ / \ | (___ ___ ____ _ ____ | |_ //
4+
// | __| | __| / /\ \ \___ \ / __| __| | _ \| __| //
5+
// | | | |____ / ____ \ ____) | (__| | | | |_) | | //
6+
// |_| |______/_/ \_\_____/ \___|_| |_| __/| | //
7+
// | | | | //
8+
// |_| | |_ //
9+
// Website: https://feascript.com/ \__| //
10+
111
import * as Comlink from "https://unpkg.com/comlink/dist/esm/comlink.mjs";
212
import { basicLog } from "./utilities/utilitiesScript.js";
313

414
export class FEAWorkerScript {
15+
/**
16+
* Constructor to initialize the FEAWorkerScript class
17+
* Sets up the worker and initializes the FEAWorkerWrapper.
18+
*/
519
constructor() {
620
this.worker = null;
721
this.feaWorker = null;
@@ -10,6 +24,11 @@ export class FEAWorkerScript {
1024
this._initWorker();
1125
}
1226

27+
/**
28+
* Initializes the web worker and wraps it using Comlink.
29+
* @private
30+
* @throws Will throw an error if the worker fails to initialize.
31+
*/
1332
async _initWorker() {
1433
try {
1534
this.worker = new Worker(
@@ -33,6 +52,12 @@ export class FEAWorkerScript {
3352
}
3453
}
3554

55+
/**
56+
* Ensures that the worker is ready before performing any operations.
57+
* @private
58+
* @returns {Promise<void>} Resolves when the worker is ready.
59+
* @throws Will throw an error if the worker is not ready within the timeout period.
60+
*/
3661
async _ensureReady() {
3762
if (this.isReady) return Promise.resolve();
3863

@@ -54,18 +79,34 @@ export class FEAWorkerScript {
5479
});
5580
}
5681

82+
/**
83+
* Sets the solver configuration in the worker.
84+
* @param {string} solverConfig - The solver configuration to set.
85+
* @returns {Promise<boolean>} Resolves when the configuration is set.
86+
*/
5787
async setSolverConfig(solverConfig) {
5888
await this._ensureReady();
5989
basicLog(`FEAWorkerScript: Setting solver config to: ${solverConfig}`);
6090
return this.feaWorker.setSolverConfig(solverConfig);
6191
}
6292

93+
/**
94+
* Sets the mesh configuration in the worker.
95+
* @param {object} meshConfig - The mesh configuration to set.
96+
* @returns {Promise<boolean>} Resolves when the configuration is set.
97+
*/
6398
async setMeshConfig(meshConfig) {
6499
await this._ensureReady();
65100
basicLog(`FEAWorkerScript: Setting mesh config`);
66101
return this.feaWorker.setMeshConfig(meshConfig);
67102
}
68103

104+
/**
105+
* Adds a boundary condition to the worker.
106+
* @param {string} boundaryKey - The key identifying the boundary.
107+
* @param {array} condition - The boundary condition to add.
108+
* @returns {Promise<boolean>} Resolves when the boundary condition is added.
109+
*/
69110
async addBoundaryCondition(boundaryKey, condition) {
70111
await this._ensureReady();
71112
basicLog(
@@ -74,12 +115,21 @@ export class FEAWorkerScript {
74115
return this.feaWorker.addBoundaryCondition(boundaryKey, condition);
75116
}
76117

118+
/**
119+
* Sets the solver method in the worker.
120+
* @param {string} solverMethod - The solver method to set.
121+
* @returns {Promise<boolean>} Resolves when the solver method is set.
122+
*/
77123
async setSolverMethod(solverMethod) {
78124
await this._ensureReady();
79125
basicLog(`FEAWorkerScript: Setting solver method to: ${solverMethod}`);
80126
return this.feaWorker.setSolverMethod(solverMethod);
81127
}
82128

129+
/**
130+
* Requests the worker to solve the problem.
131+
* @returns {Promise<object>} Resolves with the solution result.
132+
*/
83133
async solve() {
84134
await this._ensureReady();
85135
basicLog("FEAWorkerScript: Requesting solution from worker...");
@@ -97,16 +147,27 @@ export class FEAWorkerScript {
97147
return result;
98148
}
99149

150+
/**
151+
* Retrieves model information from the worker.
152+
* @returns {Promise<object>} Resolves with the model information.
153+
*/
100154
async getModelInfo() {
101155
await this._ensureReady();
102156
return this.feaWorker.getModelInfo();
103157
}
104158

159+
/**
160+
* Sends a ping request to the worker to check its availability.
161+
* @returns {Promise<boolean>} Resolves if the worker responds.
162+
*/
105163
async ping() {
106164
await this._ensureReady();
107165
return this.feaWorker.ping();
108166
}
109167

168+
/**
169+
* Terminates the worker and cleans up resources.
170+
*/
110171
terminate() {
111172
if (this.worker) {
112173
this.worker.terminate();

src/FEAWrapperScript.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// ______ ______ _____ _ _ //
2+
// | ____| ____| /\ / ____| (_) | | //
3+
// | |__ | |__ / \ | (___ ___ ____ _ ____ | |_ //
4+
// | __| | __| / /\ \ \___ \ / __| __| | _ \| __| //
5+
// | | | |____ / ____ \ ____) | (__| | | | |_) | | //
6+
// |_| |______/_/ \_\_____/ \___|_| |_| __/| | //
7+
// | | | | //
8+
// |_| | |_ //
9+
// Website: https://feascript.com/ \__| //
10+
111
import * as Comlink from "https://unpkg.com/comlink/dist/esm/comlink.mjs";
212
import { FEAScriptModel } from "./FEAScript.js";
313
import { create, all } from "https://cdn.jsdelivr.net/npm/mathjs@latest/+esm";
@@ -7,6 +17,11 @@ const math = create(all);
717
globalThis.math = math;
818

919
class FEAWorkerWrapper {
20+
/**
21+
* Constructor to initialize the FEAWorkerWrapper class.
22+
* Creates an instance of the FEAScriptModel.
23+
* @throws Will throw an error if the FEAScriptModel fails to initialize.
24+
*/
1025
constructor() {
1126
try {
1227
this.model = new FEAScriptModel();
@@ -16,6 +31,12 @@ class FEAWorkerWrapper {
1631
}
1732
}
1833

34+
/**
35+
* Sets the solver configuration in the FEAScriptModel.
36+
* @param {string} solverConfig - The solver configuration to set.
37+
* @returns {boolean} Returns true if the configuration is set successfully.
38+
* @throws Will throw an error if the configuration fails to set.
39+
*/
1940
setSolverConfig(solverConfig) {
2041
try {
2142
this.model.setSolverConfig(solverConfig);
@@ -26,6 +47,12 @@ class FEAWorkerWrapper {
2647
}
2748
}
2849

50+
/**
51+
* Sets the mesh configuration in the FEAScriptModel.
52+
* @param {object} meshConfig - The mesh configuration to set.
53+
* @returns {boolean} Returns true if the configuration is set successfully.
54+
* @throws Will throw an error if the configuration fails to set.
55+
*/
2956
setMeshConfig(meshConfig) {
3057
try {
3158
this.model.setMeshConfig(meshConfig);
@@ -36,6 +63,13 @@ class FEAWorkerWrapper {
3663
}
3764
}
3865

66+
/**
67+
* Adds a boundary condition to the FEAScriptModel.
68+
* @param {string} boundaryKey - The key identifying the boundary.
69+
* @param {array} condition - The boundary condition to add.
70+
* @returns {boolean} Returns true if the boundary condition is added successfully.
71+
* @throws Will throw an error if the boundary condition fails to add.
72+
*/
3973
addBoundaryCondition(boundaryKey, condition) {
4074
try {
4175
this.model.addBoundaryCondition(boundaryKey, condition);
@@ -46,6 +80,12 @@ class FEAWorkerWrapper {
4680
}
4781
}
4882

83+
/**
84+
* Sets the solver method in the FEAScriptModel.
85+
* @param {string} solverMethod - The solver method to set.
86+
* @returns {boolean} Returns true if the solver method is set successfully.
87+
* @throws Will throw an error if the solver method fails to set.
88+
*/
4989
setSolverMethod(solverMethod) {
5090
try {
5191
this.model.setSolverMethod(solverMethod);
@@ -56,6 +96,11 @@ class FEAWorkerWrapper {
5696
}
5797
}
5898

99+
/**
100+
* Solves the problem using the FEAScriptModel.
101+
* @returns {object} Returns the solution result, including the solution vector, node coordinates, solver configuration, and mesh dimension.
102+
* @throws Will throw an error if the solve operation fails.
103+
*/
59104
solve() {
60105
try {
61106
const result = this.model.solve();
@@ -71,6 +116,12 @@ class FEAWorkerWrapper {
71116
throw error;
72117
}
73118
}
119+
120+
/**
121+
* Retrieves model information from the FEAScriptModel.
122+
* @returns {object} Returns the model information, including solver configuration, mesh configuration, boundary conditions, and solver method.
123+
* @throws Will throw an error if the model information fails to retrieve.
124+
*/
74125
getModelInfo() {
75126
try {
76127
return {

src/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@
1111
export { FEAScriptModel } from "./FEAScript.js";
1212
export { plotSolution } from "./visualization/plotSolutionScript.js";
1313
export { printVersion, logSystem } from "./utilities/utilitiesScript.js";
14-
export { FEAWorkerScript } from "./FEAWorkerScript.js";
14+
15+
// Temporarily commenting out the worker export to avoid CORS issues
16+
// The Web Worker functionality relies on the Comlink library which is currently causing CORS errors:
17+
// - Error: "Loading module from 'https://unpkg.com/comlink/dist/esm/comlink.mjs' was blocked because of a disallowed MIME type ('text/html')"
18+
// - Error: "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource"
19+
//
20+
// export { FEAWorkerScript } from "./FEAWorkerScript.js";

0 commit comments

Comments
 (0)