initial server side setup

This commit is contained in:
Bilal Catic
2019-05-23 16:41:50 +02:00
parent b140cef88c
commit 604f952a7a
10 changed files with 3947 additions and 1 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
node_modules
.idea

2
Dockerfile Normal file
View File

@@ -0,0 +1,2 @@
FROM postgres:11.3
CMD ["postgres"]

View File

@@ -1,3 +1,32 @@
# crm-integration # crm-integration
Integrate and customize CRM and ERP used by SimaSpace Integrate and customize CRM and ERP used by SimaSpace
### Setup
1. Run setup script : `npm run setup`
This installs packages for server and client applications.
Then builds docker image for database and starts container.
Database name is `psychology`. Default username is `docker` and default password is `docker`.
If everything works correctly, it is possible to connect to database with :
`psql -d psychology -p 5432 -U docker -h localhost`
3. Start server : `npm run start-server`
4. Start client : `npm run start-client`
#### Useful NPM scripts
There are few scripts to handle some operations faster, without copy-pasting commands to terminal
1. Build docker container : `npm run docker-build`
If, for any reason, you need to build docker image, without running same image and migrations, use this script
2. Start docker container : `npm run docker-stop`
This script starts docker container if it is already built
3. Stop docker container : `npm run docker-start`
This script stops docker container
4. Execute migrations : `npm run migrate`

15
config/config.json Normal file
View File

@@ -0,0 +1,15 @@
{
"development": {
"username": "docker",
"password": "docker",
"database": "psychology",
"port": "5432",
"dialect": "postgres"
},
"test": {
"use_env_variable": "DATABASE_URL"
},
"production": {
"use_env_variable": "DATABASE_URL"
}
}

View File

@@ -0,0 +1,9 @@
'use strict';
const apiStatusCheck = (req, res) => {
res.send({status: 1});
};
module.exports = {
apiStatusCheck,
};

37
models/index.js Normal file
View File

@@ -0,0 +1,37 @@
'use strict';
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.json')[env];
const db = {};
let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}
fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
const model = sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
});
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;

3791
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

40
package.json Normal file
View File

@@ -0,0 +1,40 @@
{
"name": "psychology",
"version": "1.0.0",
"description": "Integrate and customize CRM and ERP used by SimaSpace",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"install-server": "npm install",
"install-client": "cd client && yarn install",
"docker-build": "docker build -t psychology .",
"docker-start": "docker run -e POSTGRES_USER=docker -e POSTGRES_PASSWORD=docker -e POSTGRES_DB=psychology --name pg_psychology -d -p 5432:5432 psychology",
"docker-stop": "docker stop pg_psychology",
"setup": "npm run install-server && npm run install-client && npm run docker-build && npm run docker-start && npm run migrate",
"migrate": "npx sequelize db:migrate",
"start-server": "nodemon server.js",
"start-client": "cd client && yarn start"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gitlab.com/saburly/psihologija.git"
},
"author": "Saburly",
"license": "ISC",
"engines": {
"node": "11.12.x"
},
"bugs": {
"url": "https://gitlab.com/saburly/psihologija/issues"
},
"homepage": "https://gitlab.com/saburly/psihologija#README",
"dependencies": {
"express": "^4.17.0",
"pg": "^7.11.0",
"sequelize": "^5.8.6",
"sequelize-cli": "^5.4.0"
},
"devDependencies": {
"nodemon": "^1.19.0"
}
}

10
routes/index.js Normal file
View File

@@ -0,0 +1,10 @@
'use strict';
const { apiStatusCheck } = require('../controllers/apiStatusCheck');
const express = require('express');
const router = express.Router();
router.get('/', apiStatusCheck);
module.exports = router;

10
server.js Normal file
View File

@@ -0,0 +1,10 @@
'use strict';
const express = require("express");
const routes = require('./routes');
const app = express();
const port = process.env.PORT || 5000;
app.use('/api', routes);
app.listen(port, () => console.log(`App running on port ${port}!`));