Skip to content

Commit 84c67d4

Browse files
author
Jonatan E. Salas
authored
Merge pull request #19 from BlackBoxVision/feature/heroku-deploy
Feature: Deploy service to Heroku
2 parents 2cc0c59 + 75ca23f commit 84c67d4

File tree

9 files changed

+53
-15
lines changed

9 files changed

+53
-15
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules
33
dist
44
logs/*.log
55
.nyc_output/
6-
coverage/
6+
coverage/
7+
build

Procfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This file is for Heroku deployments
2+
3+
web: node dist/src/index.js

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This starter kit comes with the following features:
1616
- **Dockerfile + docker-compose for development**
1717
- **Basic Test Suite with Tape**
1818
- **Coverage Report**
19+
- **Supports Heroku Deployment**
1920

2021
## Requirements
2122

@@ -29,6 +30,7 @@ This starter kit comes with the following features:
2930
3. Run `npm run nodemon:start`
3031
4. Visit [http://localhost:8080/documentation](http://localhost:8080/documentation) to view swagger docs.
3132
5. Visit [http://localhost:8080/api/users](http://localhost:8080/api/users) to test the REST API.
33+
6. Visit [http://localhost:8080/status](http://localhost:8080/status) to view the status monitor.
3234

3335
OUTDATED: Now there's a CLI that currently support creating a new project from this repo: [create-typescript-api](https://github.com/BlackBoxVision/create-typescript-api)
3436

@@ -44,6 +46,23 @@ This is not finished, there's still a lot of things to improve. Here you got som
4446
- [ ] Add support for TypeORM/Mongoose
4547
- [ ] Add support for Jenkins pipeline
4648

49+
## Documentation
50+
51+
### What are the package.json scripts for?
52+
53+
* `build-ts`: Compiles typescript based on config set in tsconfig.json.
54+
* `start`: Starts node with the compiled typescript. Used by eg. Heroku.
55+
* `docker:logs`: View Docker logs
56+
* `docker:ps`: List Docker containers
57+
* `docker:start`: Start Docker container based on docker-compose.yml file.
58+
* `docker:stop`: Stop Docker container
59+
* `nodemon:build`: Starts the Nodemon using ts-node. No need to compile beforehand.
60+
* `nodemon:start`: Same as nodemon:build
61+
* `format:lint`: Runs tslint on the typescipt files, based on tslint.js settings.
62+
* `format:prettier`: Runs prettier on all ts-files.
63+
* `postinstall`: Runs build-ts script. This is used by eg. Heroku automatically.
64+
* `test`: Runs tests using nyc, and creates coverage report.
65+
4766
## Issues
4867

4968
If you found a bug, or you have an answer, or whatever. Please, raise an [issue](https://github.com/BlackBoxVision/typescript-hapi-starter/issues/new).

package.json

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"node" : ">=10.0"
1313
},
1414
"scripts": {
15+
"build-ts": "tsc",
16+
"start": "node dist/src/index.js",
1517
"docker:logs": "docker-compose logs",
1618
"docker:ps": "docker-compose ps",
1719
"docker:start": "docker-compose up",
@@ -20,6 +22,7 @@
2022
"nodemon:start": "npm run nodemon:build",
2123
"format:lint": "./node_modules/.bin/tslint -c tslint.json 'src/**/*.ts'",
2224
"format:prettier": "./node_modules/.bin/prettier --tab-width 4 --print-width 120 --single-quote --trailing-comma all --write 'src/**/*.ts'",
25+
"postinstall": "npm run build-ts",
2326
"test": "NODE_ENV=test nyc --reporter=lcov --require ts-node/register tape test/**/*.spec.{ts,js} | tap-spec"
2427
},
2528
"nyc": {
@@ -31,6 +34,13 @@
3134
]
3235
},
3336
"dependencies": {
37+
"@types/code": "^4.0.5",
38+
"@types/dotenv": "^6.1.0",
39+
"@types/hapi": "^17.8.2",
40+
"@types/joi": "^14.0.1",
41+
"@types/nedb": "^1.8.3",
42+
"@types/node": "^10.12.18",
43+
"@types/tape": "^4.2.33",
3444
"hapi": "^17.8.1",
3545
"hapi-boom-decorators": "^4.1.2",
3646
"hapi-swagger": "^9.3.0",
@@ -39,17 +49,10 @@
3949
"joi": "^14.3.1",
4050
"nedb": "^1.8.0",
4151
"vision": "^5.4.4",
42-
"winston": "^3.1.0"
52+
"winston": "^3.1.0",
53+
"dotenv": "^6.2.0"
4354
},
4455
"devDependencies": {
45-
"@types/code": "^4.0.5",
46-
"@types/dotenv": "^6.1.0",
47-
"@types/hapi": "^17.8.2",
48-
"@types/joi": "^14.0.1",
49-
"@types/nedb": "^1.8.3",
50-
"@types/node": "^10.12.18",
51-
"@types/tape": "^4.2.33",
52-
"dotenv": "^6.2.0",
5356
"nodemon": "^1.11.0",
5457
"nyc": "^13.1.0",
5558
"prettier": "^1.5.2",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Logger from './helper/logger';
99
process.on('SIGINT', () => {
1010
Logger.info('Stopping hapi server');
1111

12-
Server.stop().then((err) => {
12+
Server.stop().then(err => {
1313
Logger.info(`Server stopped`);
1414
process.exit(err ? 1 : 0);
1515
});

src/model/user.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
export default class User {
2+
23
public _id: string;
3-
public age: string;
4+
public age: Number;
45
public name: string;
56
public lastName: string;
7+
8+
constructor(name: string) {
9+
this._id = "test";
10+
this.name = name;
11+
this.age = 12;
12+
this.lastName = "Smith";
13+
}
14+
15+
toString() {
16+
return `UserID: ${this._id}, Age: ${this.age}, Name: ${this.name}, LastName: ${this.lastName}`;
17+
}
618
}

src/server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export default class Server {
1515
});
1616

1717
Server._instance = new Hapi.Server({
18-
host: process.env.HOST,
1918
port: process.env.PORT,
2019
});
2120

test/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const startServer = async (): Promise<Hapi.Server> => {
1616
return await Server.recycle();
1717
};
1818

19-
export const stopServer = async (): Promise<void> => {
19+
export const stopServer = async (): Promise<void | Error> => {
2020
return await Server.stop();
2121
};
2222

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
},
5252
"exclude": [
5353
"node_modules",
54-
"**/*.spec.ts"
54+
"**/*.spec.ts",
55+
"dist"
5556
]
5657
}

0 commit comments

Comments
 (0)