Skip to content

Commit

Permalink
Merge pull request #3 from josemigallas/dev
Browse files Browse the repository at this point in the history
Adds Heroku support
  • Loading branch information
josemigallas authored Jul 21, 2017
2 parents 733345f + 3670020 commit 66d8e82
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 34 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ Then, open a different terminal and simply run:
```
$ npm test
```

## CI / CD
Continuous integration it's been done by [Travis CI](https://travis-ci.org/josemigallas/users-api). It tracks every push and PR and un the full test suite.

Additionally, the app is being deployed on Heroku, both in development (when changes are pushed to `dev`) and production (when commits are merged into `master`).

Development deployment -> https://screener-users-api-development.herokuapp.com/
Production deployment -> https://screener-users-api.herokuapp.com/users
22 changes: 6 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "users-api",
"version": "0.1.0",
"description": "This API allows all CRUDL operations over the dataset hosted in https://gist.githubusercontent.com/jasonmadigan/009c15b5dc4b4eccd32b/raw/34759c44e77d2f3515e20ed561cdd7a5e8345585/users.json.",
"version": "1.0.1",
"description": "This API allows all RESTL operations over the dataset hosted in https://gist.githubusercontent.com/jasonmadigan/009c15b5dc4b4eccd32b/raw/34759c44e77d2f3515e20ed561cdd7a5e8345585/users.json.",
"scripts": {
"start": "node dist/src/server.js",
"postinstall": "node_modules/typescript/bin/tsc -p . && cp src/repository/seed.json dist/src/repository/",
"postinstall": "node_modules/typescript/bin/tsc -p . && cp -r src/assets dist/src/assets",
"test": "node_modules/.bin/jasmine",
"posttest": "rm -r database/test",
"clean": "rm -rf node_modules database realm-object-server dist"
},
"repository": {
Expand All @@ -15,19 +16,20 @@
"author": "Jose Miguel Gallas Olmedo",
"license": "ISC",
"dependencies": {
"@types/express": "^4.0.36",
"@types/jasmine": "^2.5.53",
"@types/node": "^8.0.13",
"@types/realm": "^1.0.3",
"@types/request": "^2.0.0",
"@types/request-promise-native": "^1.0.6",
"body-parser": "^1.17.2",
"express": "^4.15.3",
"jasmine": "^2.6.0",
"realm": "^1.10.0",
"request-promise-native": "^1.0.4",
"typescript": "^2.4.1"
},
"devDependencies": {
"@types/express": "^4.0.36",
"@types/jasmine": "^2.5.53",
"@types/realm": "^1.0.3",
"@types/request-promise-native": "^1.0.6",
"jasmine": "^2.6.0"
"engines": {
"node": "4.4.7"
}
}
File renamed without changes.
11 changes: 7 additions & 4 deletions src/repository/realm-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ export default class RealmHelper {
return this._config;
}

public static init(development): void {
if (development) {
public static init(mode: string): void {
let users: User[];

if (mode === "development") {
this._config.path = "database/test/users";
users = require("../../spec/support/test-users").default;
} else {
users = require("../assets/seed.json").users;
}

const realm = this.defaultRealm;
Expand All @@ -45,8 +50,6 @@ export default class RealmHelper {
return;
}

const users: User[] = require("./seed.json").users;

realm.write(() => {
for (const user of users) {
realm.create(UserSchema.name, user);
Expand Down
2 changes: 1 addition & 1 deletion src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import User from "../model/user";
const index: Router = Router();

index.get("/", (req, res) => {
res.send("Hello from Users API!");
res.send(`Hello from Users API v${process.env.npm_package_version}!`);
});

export default index;
12 changes: 8 additions & 4 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as express from "express";
import * as bodyParser from "body-parser";

// Constants
const port: string = process.env.PORT || "3000";
const mode: string = process.env.ENV_NODE || "development";

// Server app definitions
const app: express.Express = express();

Expand All @@ -16,8 +20,8 @@ app.use("/users", users);
// Realm configuration
import RealmHelper from "./repository/realm-helper";

RealmHelper.init(process.env.ENV_NODE === "development");
RealmHelper.init(mode);

app.listen(3000, () => {
console.log(`Users API listening on port 3000 in ${process.env.ENV_NODE} mode`);
})
app.listen(port, () => {
console.log(`Users API v${process.env.npm_package_version} listening on port ${port} in ${process.env.ENV_NODE} mode`);
});

0 comments on commit 66d8e82

Please sign in to comment.