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

Commit 7517654

Browse files
committed
Added icons to the dashboard
1 parent ba73adb commit 7517654

10 files changed

+72
-67
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# User-specific stuff:
66
.idea/
77
build/
8+
icons/
89

910
## File-based project format:
1011
*.iws

.run/Run Dashboard.run.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<env name="TS_NODE_FILES" value="true"/>
77
<env name="SERVER_URL" value="http://localhost"/>
88
<env name="MASTER_KEY" value="12345678"/>
9-
<env name="APP_IDS" value="app1"/>
9+
<env name="APP_IDS" value="test"/>
1010
<env name="DASHBOARD_USERNAME" value="username"/>
1111
<env name="DASHBOARD_PASSWORD" value="password"/>
1212
</envs>

.run/Run Parse.run.xml

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<component name="ProjectRunConfigurationManager">
2-
<configuration default="false" name="Run Parse" type="NodeJSConfigurationType" node-parameters="--require ts-node/register --trace-warnings" path-to-js-file="src/parse.ts" working-dir="$PROJECT_DIR$">
3-
<envs>
4-
<env name="TS_NODE_FILES" value="true" />
5-
<env name="NODE_PORT" value="9001" />
6-
<env name="SERVER_URL" value="http://localhost" />
7-
<env name="MASTER_KEY" value="12345678" />
8-
<env name="APP_ID" value="app1" />
9-
<env name="DB_HOST" value="mongodb://db_host:27017" />
10-
<env name="DB_USERNAME" value="db_username" />
11-
<env name="DB_PASSWORD" value="db_password" />
12-
<env name="LIVE_QUERIES" value="Movie" />
13-
<env name="DELETE_ORPHANS" value="Movie" />
14-
</envs>
15-
<method v="2" />
16-
</configuration>
2+
<configuration default="false" name="Run Parse" type="NodeJSConfigurationType"
3+
node-parameters="--require ts-node/register --trace-warnings" path-to-js-file="src/parse.ts"
4+
working-dir="$PROJECT_DIR$">
5+
<envs>
6+
<env name="TS_NODE_FILES" value="true"/>
7+
<env name="NODE_PORT" value="9001"/>
8+
<env name="SERVER_URL" value="http://localhost"/>
9+
<env name="MASTER_KEY" value="12345678"/>
10+
<env name="APP_ID" value="test"/>
11+
<env name="DB_URL" value="mongodb://username:password@localhost:27017"/>
12+
<env name="LIVE_QUERIES" value="Movie"/>
13+
<env name="DELETE_ORPHANS" value="Movie"/>
14+
</envs>
15+
<method v="2"/>
16+
</configuration>
1717
</component>

README.md

+39-20
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Docker Pulls](https://img.shields.io/docker/pulls/vegidio/parse.svg)](https://hub.docker.com/r/vegidio/parse)
55
[![ISC License](https://img.shields.io/npm/l/vimdb?color=important)](LICENSE.txt)
66

7-
A Docker image for the [Parse Server](https://parseplatform.org/) with Dashboard pre-installed and a new feature to delete orphan files when a document associated with them is removed from the database.
7+
A Docker image for the [Parse Server](https://parseplatform.org/) with Dashboard pre-installed and a new feature to delete orphan files when an object associated with them is removed from the database.
88

99
It's based on [Express](https://expressjs.com) and supports single and multiple applications per instance.
1010

@@ -19,11 +19,9 @@ Run the container using the image **vegidio/parse**:
1919
```
2020
$ docker run -d \
2121
-e SERVER_URL=http://hostname \
22+
-e DB_URL=mongodb://db_host:27017 \
2223
-e MASTER_KEY=12345678 \
2324
-e APP_IDS=app1,app2 \
24-
-e DB_HOST=mongodb://database_host:27017 \
25-
-e DB_USERNAME=db_username \
26-
-e DB_PASSWORD=db_password \
2725
-e LIVE_QUERIES='app1:Movie,Actor|app2:Post' \
2826
-e DELETE_ORPHANS='app1:Review|app2:Comment' \
2927
-e DASHBOARD_USERNAME=dashboard_username \
@@ -34,12 +32,20 @@ $ docker run -d \
3432

3533
The full list of environment variables and how they can be used to configure your Parse Server can be found in the [Parameters](#-parameters) section.
3634

37-
### Multiple applications
35+
### Multiple Applications
3836

3937
If you want to run more than one application in the same instance then you just need to add them in the environment variable `APP_IDS`, in a single string separated by comma `,`.
4038

4139
For example, the environment variable `-e APP_ID=app1,app2,app3` will create 3 apps called `app1`, `app2` and `app3`.
4240

41+
### URLs
42+
43+
* __Apps:__ each app in the Parse Server can be accessed through the URL [server_url/app/`app_id`]().
44+
* __GraphQL:__ each app can also be accessed through GraphQL with the URL [server_url/app/`app_id`/graphql]().
45+
* __Dashboard:__ The Parse Dashboard can be accessed through the URL [server_url/dashboard]().
46+
47+
## ✨ Special Features
48+
4349
### Live Query
4450

4551
To enable **Live Queries** you must specify during the initialization of your Parse Server exactly what applications and classes should have this feature enabled. To do that, add the environment variable `LIVE_QUERIES` with a content with this format:
@@ -56,37 +62,50 @@ where:
5662

5763
For example, the environment variable `-e LIVE_QUERIES='app1:Movie,Actor|app2:Post'` will enable Live Queries in the classes `Movie` and `Actor` that belong to `app1`; and it will also enable Live Queries in the class `Post` that belong to `app2`.
5864

59-
### URLs
65+
### Delete Orphan Files
6066

61-
* __Apps:__ each app in the Parse Server can be accessed through the URL [hostname/app/`app_id`]().
62-
* __GraphQL:__ each app can also be accessed through GraphQL with the URL [hostname/app/`app_id`/graphql]().
63-
* __Dashboard:__ The Parse Dashboard can be accessed through the URL [hostname/dashboard]().
67+
By default, when a file is saved in the Parse Server and later deleted, only the file reference is actually removed from the database, but the file itself remains there. After some adding and removing files in the Parse Server, you will end up with many orphan files saved that are only occupying space.
6468

65-
## 🧩 Parameters
69+
To avoid this problem you can set the environment variable `DELETE_ORPHANS` with the names of the classes that must automatically removed any orphan files when an object is deleted or updated. This variable must have the following format:
6670

67-
Here is the full list of parameters used by the Parse Server:
71+
```
72+
<appId1>:<ClassA>,<ClassB>|<appId2>:<ClassC>,<ClassD>
73+
```
6874

69-
### Database Authentication
75+
where:
7076

71-
If your database requires authentication then you need to set the parameters below when you run the Parse Server, otherwise they can be ignored:
77+
- `<appId>`: is the unique ID of your parse application, followed by the colon sign (`:`).
78+
- `<Class>`: is the name of the class where the orphan files must be removed. If you want to remove orphan files from more than one class then each class must be separated by a comma (`,`).
79+
- Each application and its classes must be separated by a pipe sign (`|`).
7280

73-
- `DB_USERNAME`: the username used to login in the database. This user must have access to create new schemas.
74-
- `DB_PASSWORD`: the password used to login in the database.
81+
For example, the environment variable `-e DELETE_ORPHANS='app1:Movie,Actor|app2:Post'` will remove orphan files from the classes `Movie` and `Actor` that belong to `app1`; and it will also delete orphan files from the class `Post` that belong to `app2`.
7582

76-
### Optional
83+
## 🧩 Parameters
7784

78-
- `LIVE_QUERIES`: please see [Live Query](#live-query) above.
79-
- `DELETE_ORPHANS`: TBD
85+
Here is the full list of parameters used by the Parse Server:
8086

8187
### Mandatory
8288

83-
- `DB_HOST`: the hostname and port where the database is hosted. You **must** include here the protocol `mongodb://` or `postgres://`, according to the database that you are using.
84-
- `SERVER_URL`: the remote URL to access your Parse Server. You **must** include the protocol (`http://` or `https://`) here and the port, if needed.
89+
- `SERVER_URL`: the remote URL to access your Parse Server. You **must** include the protocol here (`http://` or `https://`) and the port, if needed.
90+
- `DB_URL`: the connection URL to the database. You **must** include here the protocol (`mongodb://` or `postgres://`) according to the database that you are using. If your database requires authentication, don't forget to include username and password as well. For example: `mongodb://username:password@localhost:27017`.
8591
- `MASTER_KEY`: the key used to grant access to the users that want to access the Parse API.
8692
- `APP_IDS`: one ore more unique IDs, separated by comma `,` to identify your apps. These IDs will also be used to form the URLs of your Parse apps.
8793
- `DASHBOARD_USERNAME`: the username used to login in the Parse Dashboard.
8894
- `DASHBOARD_PASSWORD`: the password used to login in the Parse Dashboard.
8995

96+
### Optional
97+
98+
- `LIVE_QUERIES`: please see [Live Query](#live-query) above.
99+
- `DELETE_ORPHANS`: please see [Delete Orphan Files](#delete-orphan-files) above.
100+
101+
## 🛠 Build the image
102+
103+
If you prefer to build this image yourself, instead of using the pre-built image available on [Docker Hub](https://hub.docker.com/r/vegidio/parse), then enter the following command in terminal, in the project's root directory:
104+
105+
```
106+
$ docker build -t vegidio/parse --build-arg VERSION=1.2.3 .
107+
```
108+
90109
## 📝 License
91110

92111
**vegidio/parse** is released under the ISC License. See [LICENSE](LICENSE.txt) for details.

apps.config.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,11 @@ parseArray.forEach(appId => {
4646
cwd: '/var/www/parse',
4747
exec_mode: 'cluster',
4848
env: {
49-
APP_ID: appId,
5049
NODE_PORT: port,
5150
SERVER_URL: process.env.SERVER_URL,
51+
DB_URL: process.env.DB_URL,
5252
MASTER_KEY: process.env.MASTER_KEY,
53-
DB_HOST: process.env.DB_HOST,
54-
DB_USERNAME: process.env.DB_USERNAME,
55-
DB_PASSWORD: process.env.DB_PASSWORD,
53+
APP_ID: appId,
5654
LIVE_QUERIES: liveQueryClasses,
5755
DELETE_ORPHANS: deleteOrphanClasses
5856
}

docker-compose.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ services:
77
- SERVER_URL=http://localhost
88
- MASTER_KEY=123456
99
- APP_IDS=app1,app2
10-
- DB_HOST=mongodb://mongo:27017
11-
- DB_USERNAME=username
12-
- DB_PASSWORD=password
10+
- DB_URL=mongodb://username:password@mongo:27017
1311
- LIVE_QUERIES=app1:Movie|app2:Actor
1412
- DELETE_ORPHANS=app1:Movie|app2:Actor
1513
- DASHBOARD_USERNAME=username

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@types/http-proxy-middleware": "latest",
99
"express": "latest",
1010
"http-proxy-middleware": "latest",
11+
"jdenticon": "latest",
1112
"parse-dashboard": "latest",
1213
"parse-server": "latest",
1314
"winston": "latest"

src/dashboard.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import * as fs from 'fs'
12
import * as express from 'express'
23
import * as ParseDashboard from 'parse-dashboard'
4+
import * as jdenticon from 'jdenticon'
35
import { createProxyMiddleware } from 'http-proxy-middleware'
46
import logger from './logger'
57

@@ -17,11 +19,18 @@ parseArray.forEach(appId => {
1719
apps.push({
1820
appId: appId,
1921
appName: appId,
22+
iconName: `${appId}.svg`,
2023
serverURL: `${process.env.SERVER_URL}/app/${appId}`,
21-
graphQLServerURL: `http://${process.env.SERVER_URL}/app/${appId}/graphql`,
24+
graphQLServerURL: `${process.env.SERVER_URL}/app/${appId}/graphql`,
2225
masterKey: process.env.MASTER_KEY,
2326
})
2427

28+
// Creating app icon
29+
const icon = jdenticon.toSvg(appId, 56)
30+
const iconFolder = 'icons'
31+
if(!fs.existsSync(iconFolder)) fs.mkdirSync(iconFolder)
32+
fs.writeFileSync(`${iconFolder}/${appId}.svg`, icon)
33+
2534
// Create friendly path to the app, without the port
2635
app.use(`/app/${appId}`, createProxyMiddleware({
2736
target: `http://0.0.0.0:${appPort}`,
@@ -33,6 +42,7 @@ parseArray.forEach(appId => {
3342
// Dashboard configuration
3443
const dashboard = new ParseDashboard({
3544
apps: apps,
45+
iconsFolder: 'icons',
3646
users: [{ 'user': process.env.DASHBOARD_USERNAME, 'pass': process.env.DASHBOARD_PASSWORD }]
3747
}, {
3848
allowInsecureHTTP: true

src/database.ts

-21
This file was deleted.

src/parse.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as express from 'express'
22
import ParseServer, { ParseGraphQLServer } from 'parse-server'
3-
import db from './database'
43
import cloud from './cloud'
54
import logger from './logger'
65

@@ -15,7 +14,7 @@ const parseServer = new ParseServer({
1514
appId: appId,
1615
serverURL: `http://0.0.0.0:${port}`,
1716
publicServerURL: `${process.env.SERVER_URL}/app/${appId}`,
18-
databaseURI: db.buildConnectionUrl(process.env),
17+
databaseURI: `${process.env.DB_URL}/parse_${appId}?authSource=admin`,
1918
masterKey: process.env.MASTER_KEY,
2019
liveQuery: { classNames: liveQueryArray }
2120
})

0 commit comments

Comments
 (0)