Skip to content

Commit bc08847

Browse files
Robin BuschmannRobin Buschmann
authored andcommitted
restructured; @types used
1 parent b4c8538 commit bc08847

28 files changed

+26
-210
lines changed

README.md

Lines changed: 3 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,8 @@
1-
# InterCharge (Backend)
2-
3-
This application provides a REST API for the _intercharge_ app and the _Ladestationsfinder_. It also provides a
4-
cron job scheduled data importer for _eRoamingEVSEData_ and _eRoamingEVSEStatus_ services.
5-
6-
7-
## Server Configuration
8-
9-
### Certificates
10-
11-
Before you can start any server, you have to provide a certificate and a private key for the communication with
12-
the hubject system under `certificates`.
13-
14-
#### Directory structure
15-
16-
````
17-
root
18-
- certificates/
19-
- private.key
20-
- private.crt
21-
22-
````
23-
24-
#### Add certificates via .ebextensions (certificates.config)
25-
26-
The certificates for hb authentication will be downloaded from s3 bucket to certificates directory. (Unfortunately it is not possible to download the files directly to the target dir,
27-
that's why the certificates.config contains a container command for moving the files to the final dir)
28-
29-
In addition to the `certificates.config` file, the bucket policy for the specified files has to be configured to allow elastic beanstalk to download the certificates from the source bucket.
30-
The policy should look like this:
31-
32-
````
33-
{
34-
"Id": "Policy1471940803024",
35-
"Version": "2012-10-17",
36-
"Statement": [
37-
{
38-
"Sid": "Stmt1471940796552",
39-
"Action": [
40-
"s3:GetObject"
41-
],
42-
"Effect": "Allow",
43-
"Resource": "arn:aws:s3:::intercharge-backend/*",
44-
"Principal": {
45-
"AWS": "arn:aws:iam::356886944671:role/aws-elasticbeanstalk-ec2-role"
46-
}
47-
}
48-
]
49-
}
50-
````
51-
52-
#### Saved configurations (aws)
53-
54-
There are currently 2 saved configurations for the intercharge application:
55-
- `intercharge-dev`
56-
- `intercharge-prod`
57-
58-
### Environment variables
59-
60-
The application needs some environment variables for configuration.
61-
62-
````
63-
ENVIRONMENT={development|production}
64-
HBS_EVSE_DATA_ENDPOINT={string}
65-
NODE_TLS_REJECT_UNAUTHORIZED=0
66-
HBS_EVSE_STATUS_ENDPOINT={string}
67-
DB_NAME={string}
68-
DB_DIALECT=mysql
69-
DB_USERNAME={string}
70-
DB_PWD={string}
71-
DB_HOST={string}
72-
73-
````
74-
75-
`NODE_TLS_REJECT_UNAUTHORIZED` has to be set to 0. Otherwise the self-signed certificates for the
76-
communication with hubject system will not work.
77-
78-
### DB Instances
79-
80-
#### max_allowed_packet
81-
82-
Since the data size of an evse data import exceeds the `max_allowed_packet` configured for a mysql database, it is necessary to increase this value. Therefor an DBParameterGroup has to be configured in the AWS console. (https://forums.aws.amazon.com/thread.jspa?threadID=37852)
83-
The currently used parameter group is called `intercharge-db.
84-
85-
86-
## Deployment (AWS)
87-
88-
### VPN (VPC)
89-
90-
#### How to create VPN via VPC
91-
92-
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/vpc-rds.html
93-
94-
1. Use a VPC with public and private subnets.
95-
2. Add a NAT to a public subnet and give it an Elastic IP address.
96-
3. Ensure all traffic from the private subnets goes through your NAT.
97-
4. Create your Elastic Beanstalk application, placing the ELB in a public subnet and the EC2 instances in one or more private subnets.
98-
All incoming traffic will hit your ELB and funnel to your EC2 instances. When your EC2 instances access the web service API, traffic will go through the NAT, thus appearing to originate from the static IP address.
99-
(Source: http://serverfault.com/a/638627)
100-
101-
#### VPC settings can be found in deployment config
102-
103-
`.ebextensions/deployment.config`
104-
105-
### RDS access
106-
The security group of the EC2 instance or the VPC has to be added to the security group of RDS (http://serverfault.com/a/655124). Otherwise RDS will not be accessible from the EC2 instance.
107-
108-
````
109-
Type | Protocol | Port Range | Source
110-
-------------+----------+------------+-----------
111-
MYSQL/Aurora | TCP | 3306 | sg-?????
112-
113-
````
114-
115-
### Deployment via eb-cli
116-
117-
#### Creating new environment in elasticbeanstalk via eb-cli
118-
119-
From the repo directory call `eb create <ENVIRONMENT_NAME> --cfg <SAVED_CONFIG_NAME>` to create a new environment. Pass one of the available configurations to create either a production or a development/qa instance.
120-
121-
#### Deploy new versions
122-
123-
From the repo directory select the environment, which should be updated (`eb use <ENVIRONMENT_NAME>`) and call `eb deploy`. Therefore the last changes have to be pushed to the remote repo.
124-
125-
## Running node.js server
126-
127-
To start the server use `ENVIRONMENT={development|production} ... DB_HOST={string} npm start` in command line.
128-
129-
## Stack
130-
The application is implemented in _TypeScript_. For the server implementation _express.js_ is used. The framework _sequelize_
131-
provides the orm implementation.
132-
### TypeScript
133-
The documentation for TypeScript can befound [here](https://www.typescriptlang.org/docs/tutorial.html)
134-
### express.js (server framework)
135-
Documentation for the integrated ORM _Sequelize_ can be found [here](http://expressjs.com/en/4x/api.html)
136-
### sequelize (orm)
137-
Documentation for the integrated ORM _Sequelize_ can be found [here](http://docs.sequelizejs.com/en/latest/)
138-
### ORM wrapper for sequelize
1+
# ORM wrapper for sequelize
1392
For simplicity and to prevent an interface chaos for the interaction of _TypeScript_ and _Sequelize_, a wrapper on top
1403
of both is implemented. The implementation is currently found in `orm/`.
141-
#### Definition of database models
4+
5+
## Definition of database models
1426
To define a database model you have to annotate the class(which represents you specific entity) with the `Table` and
1437
`Column` annotations. `Table` for defining the entity and `Column` for defining the column/property of the entity.
1448
For example:

package.json

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,18 @@
11
{
2-
"name": "intercharge-backend",
2+
"name": "sequelize-typescript",
33
"version": "1.0.1",
4-
"description": "Description for server-proto",
5-
"scripts": {
6-
"docs": "apidoc -i api/ -o documentation/",
7-
"compile": "tsc",
8-
"typings": "tsd install",
9-
"migrate": "db-migrate up -e db",
10-
"build": "npm run docs && npm run typings && npm run compile && npm run migrate",
11-
"prestart": "npm run build",
12-
"start": "node app.js"
13-
},
4+
"description": "Wrapper for sequelize to annotate classes",
5+
"scripts": {},
6+
"main": "dist",
147
"dependencies": {
15-
"apidoc": "^0.16.1",
16-
"bcrypt": "^0.8.5",
17-
"bluebird": "^3.2.1",
18-
"body-parser": "^1.13.3",
19-
"bookshelf": "^0.10.0",
20-
"country-language": "^0.1.7",
21-
"cron": "^1.1.0",
22-
"crypto-js": "^3.1.5",
23-
"db-migrate": "^0.10.0-beta.15",
24-
"db-migrate-mysql": "^1.1.7",
25-
"density-clustering": "^1.3.0",
26-
"di-ts": "git+https://github.com/RobinBuschmann/di-ts.git",
27-
"errorhandler": "^1.4.2",
28-
"express": "^4.13.3",
29-
"grunt-env": "^0.4.4",
30-
"jsonwebtoken": "^5.4.0",
31-
"knex": "^0.11.7",
32-
"lodash": "~2.4.1",
33-
"method-override": "^2.3.5",
34-
"morgan": "^1.6.1",
35-
"mysql": "^2.9.0",
36-
"node-uuid": "^1.4.7",
37-
"nodeadmin": "git+https://github.com/RobinBuschmann/nodeadmin.git",
38-
"reflect-metadata": "^0.1.3",
39-
"request": "^2.74.0",
40-
"sequelize": "git+https://github.com/RobinBuschmann/sequelize.git",
41-
"soap": "^0.16.0",
42-
"socket.io": "^1.4.8",
43-
"tsd": "^0.6.5",
44-
"tsd-http-status-codes": "git+https://github.com/RobinBuschmann/tsd-http-status-codes.git",
45-
"typescript": "^1.8.10",
46-
"winston": "^2.2.0"
8+
"@types/node": "^6.0.41",
9+
"@types/reflect-metadata": "0.0.4",
10+
"@types/sequelize": "^4.0.36",
11+
"sequelize": "git+https://github.com/RobinBuschmann/sequelize.git"
12+
},
13+
"devDependencies": {
14+
"typescript": "^2.0.3"
4715
},
48-
"devDependencies": {},
4916
"engines": {
5017
"node": ">=0.8.15"
5118
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)