Skip to content

Commit b4d9745

Browse files
author
Callan Milne
committed
initial commit
0 parents  commit b4d9745

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+9825
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/node_modules/
2+
*.log
3+
nohup.out
4+
/.vagrant/
5+
.DS_Store

.travis.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
language: node_js
2+
node_js:
3+
- "7"
4+
5+
env:
6+
- DS_DB_HOST=localhost MYJOURNAL_DB_USER=travis MYJOURNAL_DB_PASS= MYJOURNAL_DB_NAME=myjournal MYJOURNAL_SERVER_NAME=localhost MYJOURNAL_SERVER_PROTOCOL=http
7+
8+
services:
9+
- mysql
10+
11+
before_install:
12+
- mysql -e 'CREATE DATABASE myjournal;'
13+
14+
before_script:
15+
- export DISPLAY=:99.0
16+
- sh -e /etc/init.d/xvfb start
17+
- cat src/sql/db.sql | mysql -h localhost -u travis myjournal
18+
- cat src/sql/data/*.sql | mysql -h localhost -u travis myjournal
19+
20+
script:
21+
- npm test
22+
23+
git:
24+
depth: 10

Gulpfile.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright (c) 2019 Callan Peter Milne
3+
*
4+
* Permission to use, copy, modify, and/or distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10+
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14+
* PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
var gulp = require('gulp');
18+
var watch = require('gulp-watch');
19+
var filter = require('gulp-filter');
20+
21+
var fork = require('child_process').fork;
22+
23+
gulp.task('test', function (cb) {
24+
fork('node_modules/jasmine/bin/jasmine.js', {cwd: __dirname});
25+
});
26+
27+
gulp.task('dev', function () {
28+
return watch('**/*.js', { readDelay: 2000 }, function () {
29+
fork('node_modules/jasmine/bin/jasmine.js', {cwd: __dirname});
30+
});
31+
});

LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (c) 2019 Callan Peter Milne
2+
3+
Permission to use, copy, modify, and/or distribute this software for any
4+
purpose with or without fee is hereby granted, provided that the above
5+
copyright notice and this permission notice appear in all copies.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13+
PERFORMANCE OF THIS SOFTWARE.

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# MyJournal Web API
2+
3+
Web API for MyJournal by Eviratec
4+
5+
## Install
6+
7+
1. Install dependencies: `$ npm install`
8+
2. Create a new MySQL database
9+
3. Import SQL tables from files in `/src/sql`
10+
4. Define DB connection environment variables: `MYJOURNAL_DB_HOST`, `MYJOURNAL_DB_USER`, `MYJOURNAL_DB_PASS`, and `MYJOURNAL_DB_NAME` (e.g. `$ export MYJOURNAL_DB_HOST=localhost`)
11+
5. Test installation: `$ ./bin/test.sh`
12+
6. Start server `$ ./bin/webapi.sh`
13+
14+
## Test
15+
16+
1. Follow installation instructions above
17+
2. Run tests with `$ ./bin/test.sh`
18+
19+
## License
20+
21+
```
22+
Copyright (c) 2019 Callan Peter Milne
23+
24+
Permission to use, copy, modify, and/or distribute this software for any
25+
purpose with or without fee is hereby granted, provided that the above
26+
copyright notice and this permission notice appear in all copies.
27+
28+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
29+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
30+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
31+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
32+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
33+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
34+
PERFORMANCE OF THIS SOFTWARE.
35+
```

bin/myjournal-api

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Copyright (c) 2019 Callan Peter Milne
4+
*
5+
* Permission to use, copy, modify, and/or distribute this software for any
6+
* purpose with or without fee is hereby granted, provided that the above
7+
* copyright notice and this permission notice appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11+
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15+
* PERFORMANCE OF THIS SOFTWARE.
16+
*/
17+
18+
const DEFAULT_PORT = 8888;
19+
20+
let options = {};
21+
22+
process.argv.forEach(val => {
23+
if (!(/^--[a-z-]{0,16}=[a-z0-9-._]{0,64}$/i.test(val))) {
24+
return;
25+
}
26+
let kvPair = val.substr(2).split(/\=/);
27+
options[kvPair[0]] = kvPair[1];
28+
});
29+
30+
require("../")(options.port || DEFAULT_PORT, true);

bin/test.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
export MYJOURNAL_SOCKET="/Applications/MAMP/tmp/mysql/mysql.sock"
4+
export MYJOURNAL_DB_HOST="localhost"
5+
export MYJOURNAL_DB_USER="myjournal"
6+
export MYJOURNAL_DB_PASS="myjournal"
7+
export MYJOURNAL_DB_NAME="myjournal"
8+
9+
./node_modules/jasmine/bin/jasmine.js

bin/webapi.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
export MYJOURNAL_SOCKET="/Applications/MAMP/tmp/mysql/mysql.sock"
4+
export MYJOURNAL_DB_HOST="localhost"
5+
export MYJOURNAL_DB_USER="myjournal"
6+
export MYJOURNAL_DB_PASS="myjournal"
7+
export MYJOURNAL_DB_NAME="myjournal"
8+
9+
./bin/myjournal-api --port=3580

doc/doc.md

Whitespace-only changes.

example_nginx.conf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
upstream api_upstream {
2+
server 127.0.0.1:3000;
3+
keepalive 64;
4+
}
5+
6+
server {
7+
8+
listen 80;
9+
listen 443 ssl;
10+
11+
server_name api.myjournal.eviratec.software;
12+
13+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
14+
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
15+
ssl_prefer_server_ciphers on;
16+
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
17+
ssl_certificate /etc/nginx/ssl/api.myjournal.chain.crt;
18+
ssl_certificate_key /etc/nginx/ssl/api.myjournal.key;
19+
20+
if ($scheme = http) {
21+
return 301 https://$server_name$request_uri;
22+
}
23+
24+
location / {
25+
proxy_redirect off;
26+
proxy_set_header X-Real-IP $remote_addr;
27+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
28+
proxy_set_header X-Forwarded-Proto $scheme;
29+
proxy_set_header Host $http_host;
30+
proxy_set_header X-NginX-Proxy true;
31+
proxy_set_header Connection "";
32+
proxy_http_version 1.1;
33+
proxy_pass http://127.0.0.1:3000;
34+
}
35+
36+
}

index.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright (c) 2019 Callan Peter Milne
3+
*
4+
* Permission to use, copy, modify, and/or distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10+
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14+
* PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
const MyJournal = require("./src/app");
18+
19+
module.exports = function (port, verbose) {
20+
let myjournal = new MyJournal();
21+
22+
myjournal.server = myjournal.expressApp.listen(port, function () {
23+
verbose && console.log(`MyJournal API listening on port ${port}!`);
24+
25+
verbose && myjournal.expressApp._router.stack.forEach(layer => {
26+
try {
27+
console.log(layer.route.path);
28+
}
29+
catch (e) {
30+
// console.log(e);
31+
}
32+
});
33+
});
34+
35+
return myjournal;
36+
}

nginx.example.conf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
upstream api_upstream {
2+
server 127.0.0.1:3000;
3+
keepalive 64;
4+
}
5+
6+
server {
7+
8+
listen 80;
9+
10+
server_name api.myjournal.localhost;
11+
12+
location / {
13+
proxy_redirect off;
14+
proxy_set_header X-Real-IP $remote_addr;
15+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
16+
proxy_set_header X-Forwarded-Proto $scheme;
17+
proxy_set_header Host $http_host;
18+
proxy_set_header X-NginX-Proxy true;
19+
proxy_set_header Connection "";
20+
proxy_http_version 1.1;
21+
proxy_pass http://127.0.0.1:3000;
22+
}
23+
24+
}

0 commit comments

Comments
 (0)