Skip to content

Commit 16833b7

Browse files
Moiz KachwalaMoiz Kachwala
authored andcommitted
configured to host the application on cloud
1 parent c5de95f commit 16833b7

File tree

4 files changed

+58
-13
lines changed

4 files changed

+58
-13
lines changed

gulpfile.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ gulp.task("clientResources", () => {
7676
.pipe(gulp.dest("dist/client"));
7777
});
7878

79+
/**
80+
* Copy bin directory for www
81+
*/
82+
gulp.task("serverResources", () => {
83+
return gulp.src(["server/src/bin/**"])
84+
.pipe(gulp.dest("dist/server/bin"));
85+
});
86+
7987
/**
8088
* Copy all required libraries into build directory.
8189
*/
@@ -103,7 +111,7 @@ gulp.task("installTypings",function(){
103111
* Start the express server with nodemon
104112
*/
105113
gulp.task('start', function () {
106-
nodemon({ script: 'dist/server/server.js'
114+
nodemon({ script: 'dist/server/bin/www'
107115
, ext: 'html js'
108116
, ignore: ['ignored.js']
109117
, tasks: ['tslint'] })
@@ -122,7 +130,7 @@ gulp.task('start', function () {
122130
*/
123131

124132
gulp.task("build", function (callback) {
125-
runSequence('clean', 'build:server', 'build:client', 'clientResources', 'libs', callback);
133+
runSequence('clean', 'build:server', 'build:client', 'clientResources','serverResources', 'libs', callback);
126134
});
127135

128136
/**
@@ -150,11 +158,9 @@ gulp.task('watch', function () {
150158
*/
151159

152160
gulp.task("build", function (callback) {
153-
runSequence('clean', 'build:server', 'build:client', 'clientResources', 'libs', callback);
161+
runSequence('clean', 'build:server', 'build:client', 'clientResources','serverResources', 'libs', callback);
154162
});
155163

156-
157164
gulp.task('default', function() {
158-
runSequence( 'build:server', 'build:client', 'clientResources', 'libs','watch','start');
159-
165+
runSequence( 'build:server', 'build:client', 'clientResources','serverResources', 'libs','watch','start');
160166
});

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
"core-js": "^2.4.1",
3939
"reflect-metadata": "^0.1.3",
40-
"rxjs": "5.0.0-beta.12",
40+
"rxjs": "5.0.0-beta.11",
4141
"systemjs": "0.19.38",
4242
"zone.js": "^0.6.17",
4343

@@ -54,7 +54,7 @@
5454
"gulp-concat": "^2.6.0",
5555
"gulp-nodemon": "^2.1.0",
5656
"gulp-sourcemaps": "^1.6.0",
57-
"gulp-tslint": "^6.1.1",
57+
"gulp-tslint": "^4.3.3",
5858
"gulp-typescript": "^2.13.6",
5959
"gulp-typings": "^2.0.0",
6060
"method-override": "^2.3.6",

server/src/bin/www

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env node
2+
3+
var app = require('../server').app;
4+
var http = require('http');
5+
6+
var server = http.createServer(app);
7+
8+
server.listen(app.get('port'), function(){
9+
var host = server.address().address;
10+
var port = server.address().port;
11+
console.log('This express angular app is listening on port:' + port);
12+
});

server/src/server.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import bodyParser = require("body-parser");
66

77
import path = require('path');
88
var port: number = process.env.PORT || 3000;
9+
var env:string = process.env.NODE_ENV || 'developement';
10+
911
var app = express();
1012

13+
app.set('port', port);
14+
1115
app.use('/app', express.static(path.resolve(__dirname, '../client/app')));
1216
app.use('/libs', express.static(path.resolve(__dirname, '../client/libs')));
1317

@@ -24,8 +28,31 @@ var renderIndex = (req: express.Request, res: express.Response) => {
2428

2529
app.get('/*', renderIndex);
2630

27-
var server = app.listen(port, function() {
28-
var host = server.address().address;
29-
var port = server.address().port;
30-
console.log('This express app is listening on port:' + port);
31-
});
31+
if(env === 'developement'){
32+
app.use(function(err, req: express.Request, res: express.Response, next: express.NextFunction) {
33+
res.status(err.status || 500);
34+
res.json({
35+
error: err,
36+
message: err.message
37+
});
38+
});
39+
}
40+
41+
42+
// catch 404 and forward to error handler
43+
app.use(function(req: express.Request, res: express.Response, next) {
44+
let err = new Error("Not Found");
45+
next(err);
46+
});
47+
48+
// production error handler
49+
// no stacktrace leaked to user
50+
app.use(function(err: any, req: express.Request, res: express.Response, next: express.NextFunction) {
51+
res.status(err.status || 500);
52+
res.json({
53+
error: {},
54+
message: err.message
55+
});
56+
});
57+
58+
export { app }

0 commit comments

Comments
 (0)