11var express = require ( 'express' ) ;
2+ var bodyParser = require ( 'body-parser' ) ;
3+ var serveStatic = require ( 'serve-static' ) ;
24var port = process . env . PORT || 3000 ;
35// process是个全局变量,用来获取环境中的变量
6+ var path = require ( 'path' ) ;
47var app = express ( ) ;
58
6- app . set ( 'views' , './views' ) ;
9+ app . set ( 'views' , './views/pages ' ) ;
710// 设置视图的根目录
811app . set ( 'view engine' , 'pug' ) ;
9- // 设置默认的末班引擎
12+ // 设置默认的模板引擎
13+ // app.use(express.bodyParser()); 过版本语法,现已不支持
14+ app . use ( bodyParser . urlencoded ( ) ) ;
15+ //将表单里的数据进行格式化
16+ // app.use(express.static(path.join(__dirname,'bower_components'))); 过去版语法,现已不支持
17+ app . use ( serveStatic ( 'bower_components' ) ) ;
18+ // 设置静态目录,其实就是使view中引入的东西路径正确
1019app . listen ( port ) ;
1120// 监听端口
1221
1322console . log ( 'website started on port' + port ) ;
1423
1524app . get ( '/' , function ( req , res ) {
1625 res . render ( 'index' , {
17- title :'website 首页'
26+ title :'Movie 首页' ,
27+ movies :[ {
28+ title :'奇妙世纪 08 梦的还原器' ,
29+ _id : 1 ,
30+ poster :'http://r3.ykimg.com/05410408548589706A0A4160AF2742DF'
31+ } , {
32+ title :'奇妙世纪 08 梦的还原器' ,
33+ _id : 2 ,
34+ poster :'http://r3.ykimg.com/05410408548589706A0A4160AF2742DF'
35+ } , {
36+ title :'奇妙世纪 08 梦的还原器' ,
37+ _id : 3 ,
38+ poster :'http://r3.ykimg.com/05410408548589706A0A4160AF2742DF'
39+ } , {
40+ title :'奇妙世纪 08 梦的还原器' ,
41+ _id : 4 ,
42+ poster :'http://r3.ykimg.com/05410408548589706A0A4160AF2742DF'
43+ } , {
44+ title :'奇妙世纪 08 梦的还原器' ,
45+ _id : 5 ,
46+ poster :'http://r3.ykimg.com/05410408548589706A0A4160AF2742DF'
47+ } , {
48+ title :'奇妙世纪 08 梦的还原器' ,
49+ _id : 6 ,
50+ poster :'http://r3.ykimg.com/05410408548589706A0A4160AF2742DF'
51+ } ]
1852 } ) ;
1953} ) ;
2054// 直接调用实例的get方法
2155app . get ( '/movie/:id' , function ( req , res ) {
2256 res . render ( 'detail' , {
23- title :'website 详情页'
57+ title :'website 详情页' ,
58+ movie : {
59+ title : '奇妙世纪 08 梦的还原器' ,
60+ doctor : '程亮/林博' ,
61+ country : '大陆' ,
62+ year : 2014 ,
63+ language : '汉语' ,
64+ poster : 'http://r3.ykimg.com/05410408548589706A0A4160AF2742DF' ,
65+ flash : 'http://player.youku.com/player.php/sid/XODQ0NDk4MTA0/v.swf' ,
66+ summary : '《奇妙世纪》是由啼声影视与优酷出品共同打造的中国首部原创都市奇幻单元剧。'
67+ }
2468 } ) ;
2569} ) ;
2670app . get ( '/admin/movie' , function ( req , res ) {
2771 res . render ( 'admin' , {
28- title :'website 后台页'
72+ title :'电影 后台管理页' ,
73+ movie :{
74+ title : ' ' ,
75+ doctor : ' ' ,
76+ country : ' ' ,
77+ year : ' ' ,
78+ language : ' ' ,
79+ summary : ' ' ,
80+ poster : ' ' ,
81+ flash : ' '
82+ }
2983 } ) ;
3084} ) ;
3185app . get ( '/admin/list' , function ( req , res ) {
32- res . render ( 'list' , {
33- title :'website 列表页'
86+ res . render ( 'list' , {
87+ title :'iMovie 后台-影片列表' ,
88+ movies : [ {
89+ _id : 1 ,
90+ title : '奇妙世纪 08 梦的还原器' ,
91+ doctor : '程亮/林博' ,
92+ country : '大陆' ,
93+ year : 2014 ,
94+ language : '汉语' ,
95+ summary : '《奇妙世纪》是由啼声影视与优酷出品共同打造的中国首部原创都市奇幻单元剧。' ,
96+ poster : 'http://r3.ykimg.com/05410408548589706A0A4160AF2742DF' ,
97+ flash : 'http://player.youku.com/player.php/sid/XODQ0NDk4MTA0/v.swf'
98+ } ]
3499 } ) ;
35100} ) ;
0 commit comments