1
1
'use strict' ;
2
2
3
- var fs = require ( 'fs' ) ; //for image upload file handling
4
-
5
3
var express = require ( 'express' ) ;
6
- var app = express ( ) ;
7
-
8
- var port = 3000 ;
9
- var host = 'localhost' ;
10
- var serverPath = '/' ;
11
- var staticPath = '/' ;
12
-
13
- var staticFilePath = __dirname + serverPath ;
14
- // remove trailing slash if present
15
- if ( staticFilePath . substr ( - 1 ) === '/' ) {
16
- staticFilePath = staticFilePath . substr ( 0 , staticFilePath . length - 1 ) ;
17
- }
4
+ var http = require ( 'http' ) ;
5
+ var ipaddress = process . env . OPENSHIFT_NODEJS_IP || 'localhost' ;
6
+ var port = process . env . OPENSHIFT_NODEJS_PORT || 8080 ;
18
7
19
- app . configure ( function ( ) {
20
- // compress static content
21
- app . use ( express . compress ( ) ) ;
22
- app . use ( serverPath , express . static ( staticFilePath ) ) ; //serve static files
23
-
24
- app . use ( express . bodyParser ( ) ) ; //for post content / files - not sure if this is actually necessary?
25
- } ) ;
8
+ var app = express ( ) ;
26
9
27
- //catch all route to serve index.html (main frontend app)
28
- app . get ( '*' , function ( req , res ) {
29
- res . sendfile ( staticFilePath + staticPath + 'index.html' ) ;
10
+ // A shutdown handler to log when we quit.
11
+ process . on ( 'exit' , function ( ) {
12
+ console . log ( '%s: INFO - Node server is shutting down.' ,
13
+ Date ( Date . now ( ) ) ) ;
30
14
} ) ;
31
15
32
- app . listen ( port ) ;
33
-
34
- console . log ( 'Server running at http://' + host + ':' + port . toString ( ) + '/' ) ;
16
+ try {
17
+ app . use ( express . static ( './dist/docs' ) ) ;
18
+ console . log ( '%s: INFO - Node server started on %s:%d ...' ,
19
+ Date ( Date . now ( ) ) , ipaddress , port ) ;
20
+ http . createServer ( app ) . listen ( port , ipaddress ) ;
21
+ }
22
+ catch ( err ) {
23
+ console . log ( '%s: ERROR - Problem starting node server%s' ,
24
+ Date ( Date . now ( ) ) , err ) ;
25
+ }
0 commit comments