Toggle navigation
Toggle navigation
This project
Loading...
Sign in
허재욱
/
ComNetPrj
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
HJW
2017-11-05 12:42:17 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2114448064cf540f25bc9b22f0fae8d033f3d6d8
21144480
1 parent
604705a7
Made fortune cookie module. and applied it!
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
9 deletions
lib/fortune.js
meadowlark.js
lib/fortune.js
0 → 100644
View file @
2114448
/**
* 모듈 만들기
*/
var
fortunes
=
[
"Conquer your fears or they will conquer you."
,
"Rivers need springs."
,
"Do not fear what you don't know."
,
"You will have a pleasant surprise."
,
"Whenever possible, keep it simple."
,
];
//전역변수 추가. 모듈 밖에서도 사용할 수 있게.
exports
.
getFortune
=
function
()
{
var
idx
=
Math
.
floor
(
Math
.
random
()
*
fortunes
.
length
);
return
fortunes
[
idx
];
}
meadowlark.js
View file @
2114448
var
express
=
require
(
'express'
);
//require : 모듈 가져오는 함수
//include 와 비슷한 느낌이군.
//기본적으로 node_modules 디렉토리에서 찾는다
// ./를 붙이면 거기서 찾지 않는다.
var
fortune
=
require
(
'./lib/fortune.js'
);
var
fortunes
=
[
"Conquer your fears or they will conquer you."
,
"Rivers need springs."
,
"Do not fear what you don't know."
,
"You will have a pleasant surprise."
,
"Whenever possible, keep it simple."
,
];
var
app
=
express
();
app
.
use
(
express
.
static
(
__dirname
+
'/public'
));
...
...
@@ -21,8 +19,8 @@ app.get('/', function (req, res) {
res
.
render
(
'home'
);
});
app
.
get
(
'/about'
,
function
(
req
,
res
)
{
var
randomFortune
=
fortunes
[
Math
.
floor
(
Math
.
random
()
*
fortunes
.
length
)];
res
.
render
(
'about'
,
{
fortune
:
randomFortune
});
//
var randomFortune = fortunes[Math.floor(Math.random() * fortunes.length)];
res
.
render
(
'about'
,
{
fortune
:
fortune
.
getFortune
()
});
});
//404 Page
...
...
Please
register
or
login
to post a comment