|
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 |
139 | 2 | For simplicity and to prevent an interface chaos for the interaction of _TypeScript_ and _Sequelize_, a wrapper on top
|
140 | 3 | of both is implemented. The implementation is currently found in `orm/`.
|
141 |
| -#### Definition of database models |
| 4 | + |
| 5 | +## Definition of database models |
142 | 6 | To define a database model you have to annotate the class(which represents you specific entity) with the `Table` and
|
143 | 7 | `Column` annotations. `Table` for defining the entity and `Column` for defining the column/property of the entity.
|
144 | 8 | For example:
|
|
0 commit comments