From 72422291db5c25c890798b0da66b37670943f1f9 Mon Sep 17 00:00:00 2001 From: Braun Patrik Date: Sat, 12 Mar 2016 14:57:22 +0100 Subject: [PATCH] creating project structure --- .gitignore | 2 + backend/server.ts | 193 +++++++++++++----------- common/tsconfig.json | 15 ++ frontend/app/app.component.ts | 24 +++ frontend/app/login/login.component.css | 0 frontend/app/login/login.component.html | 1 + frontend/app/login/login.component.ts | 11 ++ frontend/index.html | 30 ++-- frontend/{app => }/main.ts | 2 +- tsconfig.json => frontend/tsconfig.json | 0 tsd.json | 9 ++ 11 files changed, 184 insertions(+), 103 deletions(-) create mode 100644 common/tsconfig.json create mode 100644 frontend/app/app.component.ts create mode 100644 frontend/app/login/login.component.css create mode 100644 frontend/app/login/login.component.html create mode 100644 frontend/app/login/login.component.ts rename frontend/{app => }/main.ts (60%) rename tsconfig.json => frontend/tsconfig.json (100%) diff --git a/.gitignore b/.gitignore index bebf57c1..61c93a13 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ node_modules/ typings/ frontend/*/*.js frontend/*/*.js.map +frontend/*.js +frontend/*.js.map backend/*/*.js backend/*/*.js.map backend/*.js diff --git a/backend/server.ts b/backend/server.ts index 9dc518cb..87431f64 100644 --- a/backend/server.ts +++ b/backend/server.ts @@ -4,101 +4,110 @@ import * as _express from 'express'; import * as _debug from 'debug'; import * as _http from 'http'; -var debug = _debug("PiGallery2:server"); -var app = _express(); + +export class Server { + + private debug:any; + private app:any; + private server:any; + private port:number; + + constructor(){ + + this.debug = _debug("PiGallery2:server"); + this.app = _express(); + + if(process.env.DEBUG) { + var _morgan = require('morgan'); + this.app.use(_morgan('dev')); + } + + + this.app.use(_express.static(__dirname +'./../frontend')); + this.app.use('/node_modules',_express.static(__dirname +'./../node_modules')); + + + + // Get port from environment and store in Express. + this.port = Server.normalizePort(process.env.PORT || '80'); + this.app.set('port', this.port); + + // Create HTTP server. + this.server = _http.createServer(this.app); + + //Listen on provided port, on all network interfaces. + this.server.listen(this.port); + this.server.on('error', this.onError); + this.server.on('listening', this.onListening); + + + } + + + /** + * Normalize a port into a number, string, or false. + */ + private static normalizePort(val) { + var port = parseInt(val, 10); + + if (isNaN(port)) { + // named pipe + return val; + } + + if (port >= 0) { + // port number + return port; + } + + return false; + } + + /** + * Event listener for HTTP server "error" event. + */ + private onError = (error) => { + if (error.syscall !== 'listen') { + throw error; + } + + var bind = typeof this.port === 'string' + ? 'Pipe ' + this.port + : 'Port ' + this.port; + + // handle specific listen errors with friendly messages + switch (error.code) { + case 'EACCES': + console.error(bind + ' requires elevated privileges'); + process.exit(1); + break; + case 'EADDRINUSE': + console.error(bind + ' is already in use'); + process.exit(1); + break; + default: + throw error; + } + }; + + + /** + * Event listener for HTTP server "listening" event. + */ + private onListening = () => { + var addr = this.server.address(); + var bind = typeof addr === 'string' + ? 'pipe ' + addr + : 'port ' + addr.port; + this.debug('Listening on ' + bind); + }; + +} + if(process.env.DEBUG) { console.log("Running in DEBUG mode"); - - import * as _morgan from 'morgan'; - app.use(_morgan('dev')); -} - - -app.use(_express.static(__dirname +'./../frontend')); -app.use('/node_modules',_express.static(__dirname +'./../node_modules')); - - - -/** - * Get port from environment and store in Express. - */ - -var port = normalizePort(process.env.PORT || '3001'); -app.set('port', port); - -/** - * Create HTTP server. - */ - -var server = _http.createServer(app); - -/** - * Listen on provided port, on all network interfaces. - */ - -server.listen(port); -server.on('error', onError); -server.on('listening', onListening); - -/** - * Normalize a port into a number, string, or false. - */ - -function normalizePort(val) { - var port = parseInt(val, 10); - - if (isNaN(port)) { - // named pipe - return val; - } - - if (port >= 0) { - // port number - return port; - } - - return false; -} - -/** - * Event listener for HTTP server "error" event. - */ - -function onError(error) { - if (error.syscall !== 'listen') { - throw error; - } - - var bind = typeof port === 'string' - ? 'Pipe ' + port - : 'Port ' + port; - - // handle specific listen errors with friendly messages - switch (error.code) { - case 'EACCES': - console.error(bind + ' requires elevated privileges'); - process.exit(1); - break; - case 'EADDRINUSE': - console.error(bind + ' is already in use'); - process.exit(1); - break; - default: - throw error; - } -} - -/** - * Event listener for HTTP server "listening" event. - */ - -function onListening() { - var addr = server.address(); - var bind = typeof addr === 'string' - ? 'pipe ' + addr - : 'port ' + addr.port; - debug('Listening on ' + bind); } +new Server(); \ No newline at end of file diff --git a/common/tsconfig.json b/common/tsconfig.json new file mode 100644 index 00000000..c5273275 --- /dev/null +++ b/common/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "es5", + "sourceMap": true, + "module": "system", + "moduleResolution": "node", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "removeComments": false + }, + "exclude": [ + "./../node_modules", + "./../typings" + ] +} \ No newline at end of file diff --git a/frontend/app/app.component.ts b/frontend/app/app.component.ts new file mode 100644 index 00000000..003e167f --- /dev/null +++ b/frontend/app/app.component.ts @@ -0,0 +1,24 @@ +import { Component } from 'angular2/core'; +import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from 'angular2/router'; +import {LoginComponent} from "./login/login.component"; + + + +@Component({ + selector: 'pi-gallery2-app', + template: ``, + directives: [ROUTER_DIRECTIVES], + providers: [ + ROUTER_PROVIDERS + ] +}) +@RouteConfig([ + { + path: '/login', + name: 'Login', + component: LoginComponent, + useAsDefault: true + } +]) +export class AppComponent { +} \ No newline at end of file diff --git a/frontend/app/login/login.component.css b/frontend/app/login/login.component.css new file mode 100644 index 00000000..e69de29b diff --git a/frontend/app/login/login.component.html b/frontend/app/login/login.component.html new file mode 100644 index 00000000..9d8b1ad7 --- /dev/null +++ b/frontend/app/login/login.component.html @@ -0,0 +1 @@ +

Login

\ No newline at end of file diff --git a/frontend/app/login/login.component.ts b/frontend/app/login/login.component.ts new file mode 100644 index 00000000..ba86194a --- /dev/null +++ b/frontend/app/login/login.component.ts @@ -0,0 +1,11 @@ +import { Component, OnInit } from 'angular2/core'; + +@Component({ + selector: 'login', + templateUrl: 'app/login/login.component.html', + styleUrls: ['app/login/login.component.css'] +}) +export class LoginComponent{ + constructor() { } +} + diff --git a/frontend/index.html b/frontend/index.html index 511abde5..e6f54d70 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -6,8 +6,7 @@ PiGallery2 - - + + + + + + + + + + -Loading... +Loading... \ No newline at end of file diff --git a/frontend/app/main.ts b/frontend/main.ts similarity index 60% rename from frontend/app/main.ts rename to frontend/main.ts index 961cb4c1..e281de44 100644 --- a/frontend/app/main.ts +++ b/frontend/main.ts @@ -1,4 +1,4 @@ import { bootstrap } from 'angular2/platform/browser'; -import { AppComponent } from './app.component'; +import { AppComponent } from './app/app.component.ts'; bootstrap(AppComponent); diff --git a/tsconfig.json b/frontend/tsconfig.json similarity index 100% rename from tsconfig.json rename to frontend/tsconfig.json diff --git a/tsd.json b/tsd.json index b1155e72..33b2c0ed 100644 --- a/tsd.json +++ b/tsd.json @@ -10,6 +10,15 @@ }, "node/node.d.ts": { "commit": "0d622d857f97d44ea7dcad2b3edec1f23c48fe9e" + }, + "debug/debug.d.ts": { + "commit": "0d622d857f97d44ea7dcad2b3edec1f23c48fe9e" + }, + "mime/mime.d.ts": { + "commit": "0d622d857f97d44ea7dcad2b3edec1f23c48fe9e" + }, + "serve-static/serve-static.d.ts": { + "commit": "0d622d857f97d44ea7dcad2b3edec1f23c48fe9e" } } }