Skip to content

Commit

Permalink
feat: refs #109848 setup base of the project
Browse files Browse the repository at this point in the history
  • Loading branch information
M0Bruno committed Jun 28, 2019
0 parents commit 923fb87
Show file tree
Hide file tree
Showing 13 changed files with 6,248 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
APP_PORT=1337
APP_PROTOCOL=http
APP_HOST=localhost

PARSE_APP_NAME=connect
PARSE_APP_ID=1234567890
PARSE_FILE_KEY=FILE_KEY
PARSE_MASTER_KEY=MASTER_KEY

MONGO_PORT=27017
MONGO_HOST=0.0.0.0
MONGO_USERNAME=connect
MONGO_PASSWORD=connect
MONGO_DB_NAME=connect
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea
node_modules/
yarn-error.log
.history
.env
logs/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12.5.0
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Connect

An open platform to save anonymous data coming from any application using this API

## Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

### Prerequisites

What things you need to install the software

```
node v12.5+
yarn v1.16+
docker-compose v1.23+
```

### Installing

Setup env variable

```
cp .env.dist .env
```

Edit the .env file to set your custom values.
Then start the docker compose to get a mongo db ready to use

```
docker-compose -d up
```

The project is ready to run

```
yarn start
```

### Running the tests

To run jest tests :

```
yarn test
```
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3.1'
services:
mongo:
image: mongo:4
ports:
- ${MONGO_PORT}:27017
volumes:
- connect-mongo-storage:/data/db
- ./docker/init-mongo.sh:/docker-entrypoint-initdb.d/init-mongo.sh
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD}
MONGO_INITDB_DATABASE: ${MONGO_DB_NAME}
mongo-express:
image: mongo-express
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: ${MONGO_USERNAME}
ME_CONFIG_MONGODB_ADMINPASSWORD: ${MONGO_PASSWORD}
node:
image: node:latest
environment:
- DEBUG=connect*
volumes:
- $PWD:/usr/src
working_dir: /usr/src
volumes:
connect-mongo-storage:
7 changes: 7 additions & 0 deletions docker/init-mongo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mongo -- "$MONGO_INITDB_DATABASE" <<EOF
var user = '$MONGO_INITDB_ROOT_USERNAME';
var passwd = '$MONGO_INITDB_ROOT_PASSWORD';
var admin = db.getSiblingDB('admin');
admin.auth(user, passwd);
db.createUser({user: user, pwd: passwd, roles: ["readWrite"]});
EOF
37 changes: 37 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "connect",
"version": "1.0.0",
"description": "",
"scripts": {
"start": "node src/index.js",
"tslint.check": "tslint",
"tslint.fix": "tslint --fix",
"prettier.check": "prettier '{src,../common}/**/*.{js}' --list-different",
"prettier.fix": "prettier '{src,../common}/**/*.{js}' --write",
"test": "jest -c jest.config.integration.js --detectOpenHandles --forceExit"
},
"prettier": {
"singleQuote": true,
"trailingComma": "all",
"semi": true,
"printWidth": 80
},
"author": "Matters",
"license": "ISC",
"dependencies": {
"dotenv": "^8.0.0",
"debug": "4.1.1",
"express": "^4.17.1",
"parse-dashboard": "1.3.3",
"parse-server": "3.4.4",
"parse-server-swagger": "0.1.0",
"winston": "^3.2.1"
},
"devDependencies": {
"jest": "^24.8.0",
"prettier": "^1.18.2",
"tslint": "^5.18.0",
"tslint-config-airbnb": "^5.11.1",
"tslint-config-prettier": "^1.18.0"
}
}
63 changes: 63 additions & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require('dotenv').config();

function testConfig(config, name) {
if (
(!config && config !== false && config !== 'false') ||
(config + '').length <= 0
) {
throw new Error(
`Undefined config ${name}: ${JSON.stringify(process.env)} `,
);
}
}

const APP_PORT = process.env.APP_PORT;
testConfig(APP_PORT, 'APP_PORT');

const APP_PROTOCOL = process.env.APP_PROTOCOL;
testConfig(APP_PROTOCOL, 'APP_PROTOCOL');

const APP_HOST = process.env.APP_HOST;
testConfig(APP_HOST, 'APP_HOST');

const PARSE_APP_NAME = process.env.PARSE_APP_NAME;
testConfig(PARSE_APP_NAME, 'PARSE_APP_NAME');

const PARSE_APP_ID = process.env.PARSE_APP_ID;
testConfig(PARSE_APP_ID, 'PARSE_APP_ID');

const PARSE_FILE_KEY = process.env.PARSE_FILE_KEY;
testConfig(PARSE_FILE_KEY, 'PARSE_FILE_KEY');

const PARSE_MASTER_KEY = process.env.PARSE_MASTER_KEY;
testConfig(PARSE_MASTER_KEY, 'PARSE_MASTER_KEY');

const MONGO_PORT = process.env.MONGO_PORT;
testConfig(MONGO_PORT, 'MONGO_PORT');

const MONGO_HOST = process.env.MONGO_HOST;
testConfig(MONGO_HOST, 'MONGO_HOST');

const MONGO_USERNAME = process.env.MONGO_USERNAME;
testConfig(MONGO_USERNAME, 'MONGO_USERNAME');

const MONGO_PASSWORD = process.env.MONGO_PASSWORD;
testConfig(MONGO_PASSWORD, 'MONGO_PASSWORD');

const MONGO_DB_NAME = process.env.MONGO_DB_NAME;
testConfig(MONGO_DB_NAME, 'MONGO_DB_NAME');

module.exports = {
APP_PORT,
APP_PROTOCOL,
APP_HOST,
PARSE_APP_NAME,
PARSE_APP_ID,
PARSE_FILE_KEY,
PARSE_MASTER_KEY,
MONGO_PORT,
MONGO_HOST,
MONGO_USERNAME,
MONGO_PASSWORD,
MONGO_DB_NAME,
};
16 changes: 16 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { APP_PORT } = require('./config');
const express = require('express');
const parseApi = require('./middleware/parse');
const parseDashboard = require('./middleware/parseDashboard');

const app = express();

// Serve the Parse API at /parse URL prefix
app.use('/parse', parseApi);
app.use('/dashboard', parseDashboard);

const port = APP_PORT || 1337;

app.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
22 changes: 22 additions & 0 deletions src/middleware/parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const {
MONGO_DB_NAME,
MONGO_HOST,
MONGO_USERNAME,
MONGO_PASSWORD,
MONGO_PORT,
PARSE_APP_NAME,
PARSE_APP_ID,
PARSE_FILE_KEY,
PARSE_MASTER_KEY,
} = require('./../config');

var ParseServer = require('parse-server').ParseServer;

module.exports = new ParseServer({
databaseURI: `mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOST}:${MONGO_PORT}/${MONGO_DB_NAME}`,
cloud: './src/parse/cloud/main.js',
appId: PARSE_APP_ID,
fileKey: PARSE_FILE_KEY,
masterKey: PARSE_MASTER_KEY,
appName: PARSE_APP_NAME,
});
20 changes: 20 additions & 0 deletions src/middleware/parseDashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var ParseDashboard = require('parse-dashboard');
const {
APP_PORT,
APP_PROTOCOL,
APP_HOST,
PARSE_APP_NAME,
PARSE_APP_ID,
PARSE_MASTER_KEY,
} = require('./../config');

module.exports = new ParseDashboard({
apps: [
{
serverURL: `${APP_PROTOCOL}://${APP_HOST}:${APP_PORT}/parse`,
appId: PARSE_APP_ID,
masterKey: PARSE_MASTER_KEY,
appName: PARSE_APP_NAME,
},
],
});
Empty file added src/parse/cloud/main.js
Empty file.
Loading

0 comments on commit 923fb87

Please sign in to comment.