Skip to content

Commit 4c6d368

Browse files
committed
Merge pull request #16 from opiepj/feature/15-server
Feature/15 server
2 parents baa299b + d3d0577 commit 4c6d368

File tree

4 files changed

+77
-18
lines changed

4 files changed

+77
-18
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,33 @@ Install the following node modules
3636
## Running App
3737
After installation run `npm run server` to start a local server using `webpack-dev-server` which will watch, build (in-memory), and reload for you. The port will be displayed to you as `http://localhost:3000` (or if you prefer IPv6, if you're using `express` server, then it's `http://[::1]:3000/`).
3838

39+
### server
40+
```bash
41+
$ webpack-dev-server
42+
```
43+
44+
## Other Commands
45+
3946
### build files
4047
```bash
41-
$ npm run build # or webpack
48+
$ webpack
4249
```
4350

4451
### watch and build files
4552
```bash
46-
$ npm run watch # or webpack --watch
53+
$ webpack --watch
4754
```
4855

4956
### run tests
5057
```bash
51-
$ npm run test # or karma start
58+
$ karma start
5259
```
5360

5461
### run webdriver (E2E)
5562
```bash
56-
$ npm run webdriver-start # or webdriver-manager start
63+
$ webdriver-manager start
5764
then
58-
$ npm rune e2e
65+
$ npm run e2e
5966
```
6067

6168
# Angular 2.0 API

package.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "angular2-webpack-starter",
2+
"name": "angular2.0-App",
33
"version": "0.0.0",
4-
"description": "An Angular 2 Webpack Starter kit featuring Angular 2 (Router, Http, Forms, Services, Tests, E2E), Karma, Protractor, Jasmine, TypeScript, and Webpack by AngularClass",
4+
"description": "An Angular 2.0 sample app using Webpack",
55
"main": "",
66
"scripts": {
77
"build": "npm run build:dev && npm run build:prod",
@@ -27,16 +27,10 @@
2727
"prestart": "npm install",
2828
"start": "npm run server"
2929
},
30-
"repository": {
31-
"type": "git",
32-
"url": "https://github.com/angular-class/angular2-webpack-starter.git"
33-
},
34-
"author": "gdi2290 <github@gdi2290.com>",
3530
"license": "MIT",
3631
"bugs": {
37-
"url": "https://github.com/angular-class/angular2-webpack-starter/issues"
32+
"url": "https://github.com/1337programming/angular2.0-App/issues"
3833
},
39-
"homepage": "https://github.com/angular-class/angular2-webpack-starter",
4034
"dependencies": {
4135
"angular2": "2.0.0-alpha.34",
4236
"reflect-metadata": "^0.1.0",

server/express-server.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Webpack
2+
var webpack = require('webpack');
3+
var WebpackDevServer = require('webpack-dev-server');
4+
var webpackConfig = require('../webpack.config');
5+
6+
// Express
7+
var express = require('express');
8+
var history = require('connect-history-api-fallback');
9+
var morgan = require('morgan');
10+
var bodyParser = require('body-parser');
11+
12+
// Express App
13+
var app = express();
14+
15+
// Env
16+
var PORT = process.env.PORT || 3000;
17+
var NODE_ENV = process.env.NODE_ENV || 'development';
18+
19+
app.use(morgan('dev'));
20+
app.use(bodyParser.json());
21+
app.use(bodyParser.urlencoded({
22+
extended: true
23+
}));
24+
25+
// Angular Http content type for POST etc defaults to text/plain at
26+
app.use(bodyParser.text(), function ngHttpFix(req, next) {
27+
try {
28+
req.body = JSON.parse(req.body);
29+
next();
30+
} catch (e) {
31+
next();
32+
}
33+
});
34+
35+
// Your middleware
36+
app.use(history());
37+
app.use(express.static('src/public'));
38+
39+
// Only use in development
40+
if (NODE_ENV === 'development') {
41+
var server = new WebpackDevServer(webpack(webpackConfig), {
42+
publicPath: '/__build__',
43+
historyApiFallback: false, // won't work due to order
44+
inline: true,
45+
quiet: false,
46+
noInfo: false,
47+
stats: {
48+
colors: true
49+
}
50+
});
51+
// Webpack express app that uses socket.io
52+
app.use(server.app);
53+
} else {
54+
app.use('/__build__', express.static('__build__'));
55+
}
56+
57+
58+
app.listen(PORT, function () {
59+
console.log('Listen on http://localhost:' + PORT + ' in ' + NODE_ENV);
60+
});

src/public/index.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<!DOCTYPE html>
22
<html lang="">
33
<head>
4-
<title>Angular2 Webpack Starter by @gdi2990 from @AngularClass</title>
4+
<title>Angular 2.0 App</title>
55

66
<meta charset="utf-8">
77
<meta http-equiv="X-UA-Compatible" content="IE=edge">
88
<meta name="description" content="">
99
<meta name="viewport" content="width=device-width, initial-scale=1">
1010
<meta http-equiv="X-UA-Compatible" content="IE=edge">
11-
<meta name="description" content="Angular2 Webpack Starter by @gdi2990 from @AngularClass">
1211
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
1312

1413
<base href="/">
@@ -38,7 +37,6 @@
3837
<!-- Angular2 files -->
3938
<script src="/__build__/angular2.js"></script>
4039
<!-- App script -->
41-
<script src="/__build__/app-simple.js"></script>
42-
<!-- TODO: replace /app-simple.js with /app.js -->
40+
<script src="/__build__/app.js"></script>
4341
</body>
4442
</html>

0 commit comments

Comments
 (0)