@formio/appserver 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -2
- package/lib/db.d.ts +3 -1
- package/lib/db.js +14 -9
- package/lib/index.js +2 -1
- package/lib/types/server.d.ts +2 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ const app = express();
|
|
|
16
16
|
const { Server } = require('@formio/appserver');
|
|
17
17
|
(async function bootup() {
|
|
18
18
|
// Create the server.
|
|
19
|
-
const server =
|
|
19
|
+
const server = new Server();
|
|
20
20
|
|
|
21
21
|
// Initialize the server.
|
|
22
22
|
await server.init();
|
|
@@ -50,6 +50,33 @@ Now, within the ```.env``` file, modify all of the environment variables to be t
|
|
|
50
50
|
node index
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
### Environment Variables
|
|
54
|
+
This library uses environment variables to configure the configurations required to run the server. These are as follows.
|
|
55
|
+
|
|
56
|
+
| Variable Name | Required | Description | Example |
|
|
57
|
+
|--------------|:-----:|-----------:|
|
|
58
|
+
| MONGO | yes | Your MongoDB Connection string to use the default DB. | mongodb://localhost:27017/appserver |
|
|
59
|
+
| PROJECT_ENDPOINT | yes | The endpoint for your deployed Form.io Enterprise project. | https://mydeployment.com/myproject |
|
|
60
|
+
| PROJECT_KEY | yes | The API Key for your deployed Form.io Enterprise Project. | abc123 |
|
|
61
|
+
| LICENSE_KEY | yes | Your License Key for this AppServer deployment. | <LONG LICENSE KEY> |
|
|
62
|
+
| PORT | no | The port that your server will run on. Default 3005 | 3005 |
|
|
63
|
+
| JWT_SECRET | yes | The key used to protect your JWT authentication tokens. | YOUR_SECRET_KEY |
|
|
64
|
+
| JWT_EXPIRE_TIME | no | The number of minutes to expire your JWT token. | 240 |
|
|
65
|
+
| PORTAL_SECRET | no | Provides the ability to connect to the AppServer via the Remote Environment Connection within your Developer Portal. | YOUR_SECRET_KEY |
|
|
66
|
+
| PROJECT_CACHE | no | Disables the cache for project resources (such as Project template, Project Settings, and Access Settings). Default "true" | true |
|
|
67
|
+
| MONGO_CONFIG | no | Additional configurations to add to the DB connection string | {} |
|
|
68
|
+
|
|
69
|
+
### Developer Portal Connection
|
|
70
|
+
Once you have the AppServer running within your own environment, and connected to your own database, you can now deploy your new changes to your forms, resources, project settings, etc. To accomplish this, you must first run the AppServer using the ```PORTAL_SECRET``` described above.
|
|
71
|
+
|
|
72
|
+
Once you have this set, you can then log into your Developer Portal, and then navigate to your Project.
|
|
73
|
+
|
|
74
|
+
Once there, you will then go to your **Staging | Connect Environment**. Here you will put your AppServer endpoint and the PORTAL_SECRET value. You will then want to set the **Project Path Type** to use **Subdirectory**. Then click **Continue**.
|
|
75
|
+
|
|
76
|
+
You will then see the next page, where you will select your Stage in the dropdown. You should see it since the AppServer connects to the project on bootup.
|
|
77
|
+
|
|
78
|
+
Once you are connected, any changes you make within the Developer portal will now be directly reflected within your AppServer deployment.
|
|
79
|
+
|
|
53
80
|
### Custom Configuration
|
|
54
81
|
The AppServer is very extensible, and many things can be altered and modified as well as custom implementations of different components are possible using configurations.
|
|
55
82
|
|
|
@@ -64,7 +91,7 @@ const { CustomAuth } = require('./customAuth');
|
|
|
64
91
|
const { CustomAction } = require('./actions/custom');
|
|
65
92
|
(async function bootup() {
|
|
66
93
|
// Create the server.
|
|
67
|
-
const server =
|
|
94
|
+
const server = new Server({
|
|
68
95
|
/**
|
|
69
96
|
* The "db" configuration provides a way to use a Custom database implementation.
|
|
70
97
|
*
|
package/lib/db.d.ts
CHANGED
|
@@ -6,14 +6,16 @@ export declare class Database implements ServerDB {
|
|
|
6
6
|
currentCollectionName: string;
|
|
7
7
|
currentCollection: Collection<Document> | null;
|
|
8
8
|
defaultCollection: Collection<Document> | null;
|
|
9
|
+
prefix: string;
|
|
9
10
|
constructor(config: DBConfig);
|
|
10
11
|
ObjectId(id: any): any;
|
|
12
|
+
collectionName(name: string): string;
|
|
11
13
|
/**
|
|
12
14
|
* Connect to the database.
|
|
13
15
|
* @param {*} scope
|
|
14
16
|
* @returns
|
|
15
17
|
*/
|
|
16
|
-
connect(): Promise<void>;
|
|
18
|
+
connect(prefix?: string): Promise<void>;
|
|
17
19
|
save(collectionName: string, item: any): Promise<import("mongodb").WithId<import("bson").Document> | null>;
|
|
18
20
|
load(collectionName: string): Promise<import("mongodb").WithId<import("bson").Document> | null | undefined>;
|
|
19
21
|
remove(collectionName: string): Promise<number | null>;
|
package/lib/db.js
CHANGED
|
@@ -21,6 +21,7 @@ const error = require('debug')('formio:error');
|
|
|
21
21
|
class Database {
|
|
22
22
|
constructor(config) {
|
|
23
23
|
this.config = config;
|
|
24
|
+
this.prefix = '';
|
|
24
25
|
this.db = null;
|
|
25
26
|
this.currentCollectionName = 'submissions';
|
|
26
27
|
this.currentCollection = null;
|
|
@@ -37,21 +38,25 @@ class Database {
|
|
|
37
38
|
return id;
|
|
38
39
|
}
|
|
39
40
|
}
|
|
41
|
+
collectionName(name) {
|
|
42
|
+
return `${this.prefix}${name}`;
|
|
43
|
+
}
|
|
40
44
|
/**
|
|
41
45
|
* Connect to the database.
|
|
42
46
|
* @param {*} scope
|
|
43
47
|
* @returns
|
|
44
48
|
*/
|
|
45
|
-
connect() {
|
|
49
|
+
connect(prefix = '') {
|
|
46
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
this.prefix = prefix ? `${prefix}.` : '';
|
|
47
52
|
try {
|
|
48
53
|
debug('db.connect()');
|
|
49
54
|
const config = this.config.config ? JSON.parse(this.config.config) : {};
|
|
50
55
|
const client = new mongodb_1.MongoClient(this.config.url, config);
|
|
51
56
|
yield client.connect();
|
|
52
57
|
this.db = yield client.db();
|
|
53
|
-
this.addIndex(this.db.collection('project'), 'name');
|
|
54
|
-
this.defaultCollection = this.db.collection('submissions');
|
|
58
|
+
this.addIndex(this.db.collection(this.collectionName('project')), 'name');
|
|
59
|
+
this.defaultCollection = this.db.collection(this.collectionName('submissions'));
|
|
55
60
|
yield this.setupIndexes(this.defaultCollection);
|
|
56
61
|
debug('Connected to database');
|
|
57
62
|
}
|
|
@@ -67,7 +72,7 @@ class Database {
|
|
|
67
72
|
if (!this.db) {
|
|
68
73
|
return null;
|
|
69
74
|
}
|
|
70
|
-
const collection = this.db.collection(collectionName);
|
|
75
|
+
const collection = this.db.collection(`${this.prefix}${collectionName}`);
|
|
71
76
|
let result;
|
|
72
77
|
try {
|
|
73
78
|
debug('db.save()', collectionName);
|
|
@@ -86,7 +91,7 @@ class Database {
|
|
|
86
91
|
return null;
|
|
87
92
|
}
|
|
88
93
|
debug('db.load()', collectionName);
|
|
89
|
-
const collection = this.db.collection(collectionName);
|
|
94
|
+
const collection = this.db.collection(this.collectionName(collectionName));
|
|
90
95
|
let item;
|
|
91
96
|
try {
|
|
92
97
|
item = yield collection.findOne({});
|
|
@@ -104,7 +109,7 @@ class Database {
|
|
|
104
109
|
return null;
|
|
105
110
|
}
|
|
106
111
|
debug('db.remove()', collectionName);
|
|
107
|
-
const collection = this.db.collection(collectionName);
|
|
112
|
+
const collection = this.db.collection(this.collectionName(collectionName));
|
|
108
113
|
let result;
|
|
109
114
|
try {
|
|
110
115
|
result = yield collection.deleteOne({});
|
|
@@ -129,14 +134,14 @@ class Database {
|
|
|
129
134
|
let collection = null;
|
|
130
135
|
try {
|
|
131
136
|
debug('db.createCollection()', scope.form.settings.collection);
|
|
132
|
-
yield this.db.createCollection(scope.form.settings.collection);
|
|
133
|
-
collection = this.db.collection(scope.form.settings.collection);
|
|
137
|
+
yield this.db.createCollection(this.collectionName(scope.form.settings.collection));
|
|
138
|
+
collection = this.db.collection(this.collectionName(scope.form.settings.collection));
|
|
134
139
|
this.setupIndexes(collection, scope);
|
|
135
140
|
}
|
|
136
141
|
catch (err) {
|
|
137
142
|
error(err.message);
|
|
138
143
|
}
|
|
139
|
-
this.currentCollection = collection || this.db.collection(scope.form.settings.collection);
|
|
144
|
+
this.currentCollection = collection || this.db.collection(this.collectionName(scope.form.settings.collection));
|
|
140
145
|
this.currentCollectionName = scope.form.settings.collection;
|
|
141
146
|
return this.currentCollection;
|
|
142
147
|
}
|
package/lib/index.js
CHANGED
package/lib/types/server.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export interface DBConfig {
|
|
|
41
41
|
}
|
|
42
42
|
export interface ServerDB {
|
|
43
43
|
config: DBConfig;
|
|
44
|
-
connect: () => Promise<void>;
|
|
44
|
+
connect: (prefix?: string) => Promise<void>;
|
|
45
45
|
save: (collection: string, doc: any) => Promise<any>;
|
|
46
46
|
load: (collection: string) => Promise<any>;
|
|
47
47
|
remove: (collection: string) => Promise<any>;
|
|
@@ -100,4 +100,5 @@ export interface AppServerScope {
|
|
|
100
100
|
processors?: Array<(scope: ProcessScope) => Promise<any[]>>;
|
|
101
101
|
preppers?: Preppers;
|
|
102
102
|
actions?: any;
|
|
103
|
+
hooks?: any;
|
|
103
104
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formio/appserver",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "A highly performant and extensible Application Server for Form.io Multi-Tenant Deployments.",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
],
|
|
26
26
|
"homepage": "https://github.com/formio/appserver#readme",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@formio/appserver-core": "^1.3.
|
|
28
|
+
"@formio/appserver-core": "^1.3.4",
|
|
29
29
|
"@formio/appserver-types": "^1.2.1",
|
|
30
30
|
"async": "^3.2.4",
|
|
31
31
|
"bcryptjs": "^2.4.3",
|