Skip to content

Commit b1fee99

Browse files
committed
Initial commit
1 parent 5ae9012 commit b1fee99

File tree

8 files changed

+95
-0
lines changed

8 files changed

+95
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
*~
3+
.DS_Store

app.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
var express = require('express');
2+
var app = express();
3+
var handlebars = require('express3-handlebars').create({defaultLayout : 'main'});
4+
var fortunes = [
5+
"Conquer your fears or they will conquer you .",
6+
"River need springs.",
7+
"Do not fear what you don't know.",
8+
"You will hava a pleasant surprese.",
9+
"Whenever possoble , keep it simple.",
10+
];
11+
12+
app.engine('handlebars' , handlebars.engine);
13+
app.set('view engine' , 'handlebars');
14+
15+
app.set('port' , process.env.PORT || 3002);
16+
app.use(express.static(__dirname +'/public'));
17+
//¶¨ÖÆ404Ò³Ãæ
18+
app.get('/' , function(req , res){
19+
//res.type('text/plain');
20+
//res.send('FirtTest');
21+
res.render('home');
22+
});
23+
app.get('/about', function(req , res){
24+
//res.type('text/plain');
25+
//res.send('About');
26+
var randomFortune = fortunes[Math.floor(Math.random()*fortunes.length)];
27+
res.render('about' , {fortune : randomFortune});
28+
});
29+
app.use(function(req , res){
30+
//res.type('text/plain');
31+
res.status(404);
32+
res.render('404');
33+
//res.send('404-NotFound');
34+
});
35+
//¶¨ÖÆ500Ò³Ãæ
36+
app.use(function(err , req , res , next){
37+
console.error(err.stack);
38+
//res.type('text/plain');
39+
res.status(500);
40+
//res.send('500-ServerError');
41+
res.render('500');
42+
});
43+
44+
app.listen(app.get('port') , function(){
45+
console.log('Express started on http://13.199.168.15:' + app.get('port') + ';pressCtrl-C to terminate.');
46+
});

package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "exfirsttest",
3+
"version": "1.0.0",
4+
"description": "My first express project",
5+
"main": "app.js",
6+
"dependencies": {
7+
"express": "^4.14.0"
8+
},
9+
"devDependencies": {},
10+
"scripts": {
11+
"test": "command"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/magicxin/exFirstTest.git"
16+
},
17+
"keywords": [
18+
"531441"
19+
],
20+
"author": "magic_xin",
21+
"license": "ISC",
22+
"bugs": {
23+
"url": "https://github.com/magicxin/exFirstTest/issues"
24+
},
25+
"homepage": "https://github.com/magicxin/exFirstTest#readme"
26+
}

views/404.handlebars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>404 NOT FOUND</h1>

views/500.handlebars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>500-SERVERERROR</h1>

views/about.handlebars

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<h1> This is about page</h1>
2+
3+
<p>You fortune for the day:</p>
4+
<blockquote>{{fortune}}</blockquote>

views/home.handlebars

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h1>Welcome to my first express test</h1>
2+
<p>test p</p>

views/layouts/main.handlebars

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>exFirstTest</title>
5+
</head>
6+
<body>
7+
<header>
8+
<img src="/img/logo.jpg" alt="exFirstTest Logo" />
9+
</header>
10+
{{{body}}}
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)