Skip to content

Commit 923fb87

Browse files
author
M0Bruno
committed
feat: refs #109848 setup base of the project
0 parents  commit 923fb87

File tree

13 files changed

+6248
-0
lines changed

13 files changed

+6248
-0
lines changed

.env.dist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
APP_PORT=1337
2+
APP_PROTOCOL=http
3+
APP_HOST=localhost
4+
5+
PARSE_APP_NAME=connect
6+
PARSE_APP_ID=1234567890
7+
PARSE_FILE_KEY=FILE_KEY
8+
PARSE_MASTER_KEY=MASTER_KEY
9+
10+
MONGO_PORT=27017
11+
MONGO_HOST=0.0.0.0
12+
MONGO_USERNAME=connect
13+
MONGO_PASSWORD=connect
14+
MONGO_DB_NAME=connect

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea
2+
node_modules/
3+
yarn-error.log
4+
.history
5+
.env
6+
logs/

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12.5.0

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Connect
2+
3+
An open platform to save anonymous data coming from any application using this API
4+
5+
## Getting Started
6+
7+
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
8+
9+
### Prerequisites
10+
11+
What things you need to install the software
12+
13+
```
14+
node v12.5+
15+
yarn v1.16+
16+
docker-compose v1.23+
17+
```
18+
19+
### Installing
20+
21+
Setup env variable
22+
23+
```
24+
cp .env.dist .env
25+
```
26+
27+
Edit the .env file to set your custom values.
28+
Then start the docker compose to get a mongo db ready to use
29+
30+
```
31+
docker-compose -d up
32+
```
33+
34+
The project is ready to run
35+
36+
```
37+
yarn start
38+
```
39+
40+
### Running the tests
41+
42+
To run jest tests :
43+
44+
```
45+
yarn test
46+
```

docker-compose.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
version: '3.1'
2+
services:
3+
mongo:
4+
image: mongo:4
5+
ports:
6+
- ${MONGO_PORT}:27017
7+
volumes:
8+
- connect-mongo-storage:/data/db
9+
- ./docker/init-mongo.sh:/docker-entrypoint-initdb.d/init-mongo.sh
10+
environment:
11+
MONGO_INITDB_ROOT_USERNAME: ${MONGO_USERNAME}
12+
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD}
13+
MONGO_INITDB_DATABASE: ${MONGO_DB_NAME}
14+
mongo-express:
15+
image: mongo-express
16+
ports:
17+
- 8081:8081
18+
environment:
19+
ME_CONFIG_MONGODB_ADMINUSERNAME: ${MONGO_USERNAME}
20+
ME_CONFIG_MONGODB_ADMINPASSWORD: ${MONGO_PASSWORD}
21+
node:
22+
image: node:latest
23+
environment:
24+
- DEBUG=connect*
25+
volumes:
26+
- $PWD:/usr/src
27+
working_dir: /usr/src
28+
volumes:
29+
connect-mongo-storage:

docker/init-mongo.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
mongo -- "$MONGO_INITDB_DATABASE" <<EOF
2+
var user = '$MONGO_INITDB_ROOT_USERNAME';
3+
var passwd = '$MONGO_INITDB_ROOT_PASSWORD';
4+
var admin = db.getSiblingDB('admin');
5+
admin.auth(user, passwd);
6+
db.createUser({user: user, pwd: passwd, roles: ["readWrite"]});
7+
EOF

package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "connect",
3+
"version": "1.0.0",
4+
"description": "",
5+
"scripts": {
6+
"start": "node src/index.js",
7+
"tslint.check": "tslint",
8+
"tslint.fix": "tslint --fix",
9+
"prettier.check": "prettier '{src,../common}/**/*.{js}' --list-different",
10+
"prettier.fix": "prettier '{src,../common}/**/*.{js}' --write",
11+
"test": "jest -c jest.config.integration.js --detectOpenHandles --forceExit"
12+
},
13+
"prettier": {
14+
"singleQuote": true,
15+
"trailingComma": "all",
16+
"semi": true,
17+
"printWidth": 80
18+
},
19+
"author": "Matters",
20+
"license": "ISC",
21+
"dependencies": {
22+
"dotenv": "^8.0.0",
23+
"debug": "4.1.1",
24+
"express": "^4.17.1",
25+
"parse-dashboard": "1.3.3",
26+
"parse-server": "3.4.4",
27+
"parse-server-swagger": "0.1.0",
28+
"winston": "^3.2.1"
29+
},
30+
"devDependencies": {
31+
"jest": "^24.8.0",
32+
"prettier": "^1.18.2",
33+
"tslint": "^5.18.0",
34+
"tslint-config-airbnb": "^5.11.1",
35+
"tslint-config-prettier": "^1.18.0"
36+
}
37+
}

src/config/index.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
require('dotenv').config();
2+
3+
function testConfig(config, name) {
4+
if (
5+
(!config && config !== false && config !== 'false') ||
6+
(config + '').length <= 0
7+
) {
8+
throw new Error(
9+
`Undefined config ${name}: ${JSON.stringify(process.env)} `,
10+
);
11+
}
12+
}
13+
14+
const APP_PORT = process.env.APP_PORT;
15+
testConfig(APP_PORT, 'APP_PORT');
16+
17+
const APP_PROTOCOL = process.env.APP_PROTOCOL;
18+
testConfig(APP_PROTOCOL, 'APP_PROTOCOL');
19+
20+
const APP_HOST = process.env.APP_HOST;
21+
testConfig(APP_HOST, 'APP_HOST');
22+
23+
const PARSE_APP_NAME = process.env.PARSE_APP_NAME;
24+
testConfig(PARSE_APP_NAME, 'PARSE_APP_NAME');
25+
26+
const PARSE_APP_ID = process.env.PARSE_APP_ID;
27+
testConfig(PARSE_APP_ID, 'PARSE_APP_ID');
28+
29+
const PARSE_FILE_KEY = process.env.PARSE_FILE_KEY;
30+
testConfig(PARSE_FILE_KEY, 'PARSE_FILE_KEY');
31+
32+
const PARSE_MASTER_KEY = process.env.PARSE_MASTER_KEY;
33+
testConfig(PARSE_MASTER_KEY, 'PARSE_MASTER_KEY');
34+
35+
const MONGO_PORT = process.env.MONGO_PORT;
36+
testConfig(MONGO_PORT, 'MONGO_PORT');
37+
38+
const MONGO_HOST = process.env.MONGO_HOST;
39+
testConfig(MONGO_HOST, 'MONGO_HOST');
40+
41+
const MONGO_USERNAME = process.env.MONGO_USERNAME;
42+
testConfig(MONGO_USERNAME, 'MONGO_USERNAME');
43+
44+
const MONGO_PASSWORD = process.env.MONGO_PASSWORD;
45+
testConfig(MONGO_PASSWORD, 'MONGO_PASSWORD');
46+
47+
const MONGO_DB_NAME = process.env.MONGO_DB_NAME;
48+
testConfig(MONGO_DB_NAME, 'MONGO_DB_NAME');
49+
50+
module.exports = {
51+
APP_PORT,
52+
APP_PROTOCOL,
53+
APP_HOST,
54+
PARSE_APP_NAME,
55+
PARSE_APP_ID,
56+
PARSE_FILE_KEY,
57+
PARSE_MASTER_KEY,
58+
MONGO_PORT,
59+
MONGO_HOST,
60+
MONGO_USERNAME,
61+
MONGO_PASSWORD,
62+
MONGO_DB_NAME,
63+
};

src/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { APP_PORT } = require('./config');
2+
const express = require('express');
3+
const parseApi = require('./middleware/parse');
4+
const parseDashboard = require('./middleware/parseDashboard');
5+
6+
const app = express();
7+
8+
// Serve the Parse API at /parse URL prefix
9+
app.use('/parse', parseApi);
10+
app.use('/dashboard', parseDashboard);
11+
12+
const port = APP_PORT || 1337;
13+
14+
app.listen(port, function() {
15+
console.log('parse-server-example running on port ' + port + '.');
16+
});

src/middleware/parse.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const {
2+
MONGO_DB_NAME,
3+
MONGO_HOST,
4+
MONGO_USERNAME,
5+
MONGO_PASSWORD,
6+
MONGO_PORT,
7+
PARSE_APP_NAME,
8+
PARSE_APP_ID,
9+
PARSE_FILE_KEY,
10+
PARSE_MASTER_KEY,
11+
} = require('./../config');
12+
13+
var ParseServer = require('parse-server').ParseServer;
14+
15+
module.exports = new ParseServer({
16+
databaseURI: `mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOST}:${MONGO_PORT}/${MONGO_DB_NAME}`,
17+
cloud: './src/parse/cloud/main.js',
18+
appId: PARSE_APP_ID,
19+
fileKey: PARSE_FILE_KEY,
20+
masterKey: PARSE_MASTER_KEY,
21+
appName: PARSE_APP_NAME,
22+
});

src/middleware/parseDashboard.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var ParseDashboard = require('parse-dashboard');
2+
const {
3+
APP_PORT,
4+
APP_PROTOCOL,
5+
APP_HOST,
6+
PARSE_APP_NAME,
7+
PARSE_APP_ID,
8+
PARSE_MASTER_KEY,
9+
} = require('./../config');
10+
11+
module.exports = new ParseDashboard({
12+
apps: [
13+
{
14+
serverURL: `${APP_PROTOCOL}://${APP_HOST}:${APP_PORT}/parse`,
15+
appId: PARSE_APP_ID,
16+
masterKey: PARSE_MASTER_KEY,
17+
appName: PARSE_APP_NAME,
18+
},
19+
],
20+
});

src/parse/cloud/main.js

Whitespace-only changes.

0 commit comments

Comments
 (0)