Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
L
loaf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
toby
loaf
Commits
0a549d09
Commit
0a549d09
authored
Jun 25, 2016
by
toby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
de-side-effect app
parent
1163bfa5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
116 deletions
+119
-116
app.js
app.js
+117
-0
loaf
bin/loaf
+2
-116
No files found.
app.js
0 → 100644
View file @
0a549d09
const
debug
=
require
(
'debug'
)(
'loafer:server'
);
const
http
=
require
(
'http'
);
const
exec
=
require
(
'child_process'
).
exec
;
const
express
=
require
(
'express'
);
const
path
=
require
(
'path'
);
const
favicon
=
require
(
'serve-favicon'
);
const
logger
=
require
(
'morgan'
);
const
cookieParser
=
require
(
'cookie-parser'
);
const
bodyParser
=
require
(
'body-parser'
);
const
routes
=
require
(
'./routes/index'
);
const
app
=
express
();
/**
* Get port and normalize into a number, string, or false.
*/
function
normalizedPort
()
{
const
val
=
process
.
env
.
PORT
||
'3011'
;
const
port
=
parseInt
(
val
,
10
);
if
(
isNaN
(
port
))
{
// named pipe
return
val
;
}
if
(
port
>=
0
)
{
// port number
return
port
;
}
return
false
;
}
function
configureApp
(
port
)
{
app
.
set
(
'port'
,
port
);
app
.
set
(
'views'
,
path
.
join
(
__dirname
,
'/./views'
));
app
.
set
(
'view engine'
,
'pug'
);
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app
.
use
(
logger
(
'dev'
));
app
.
use
(
bodyParser
.
json
());
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}));
app
.
use
(
cookieParser
());
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'/./public'
)));
app
.
use
(
'/'
,
routes
);
// catch 404 and forward to error handler
app
.
use
(
function
(
req
,
res
,
next
)
{
const
err
=
new
Error
(
'Not Found'
);
err
.
status
=
404
;
next
(
err
);
});
// development error handler
// will print stacktrace
if
(
app
.
get
(
'env'
)
===
'development'
)
{
app
.
use
(
function
(
err
,
req
,
res
,
next
)
{
res
.
status
(
err
.
status
||
500
);
res
.
render
(
'error'
,
{
message
:
err
.
message
,
error
:
err
});
});
}
// production error handler
// no stacktraces leaked to user
app
.
use
(
function
(
err
,
req
,
res
,
next
)
{
res
.
status
(
err
.
status
||
500
);
res
.
render
(
'error'
,
{
message
:
err
.
message
,
error
:
{}
});
});
return
app
;
}
function
httpListen
(
app
)
{
const
server
=
http
.
createServer
(
app
);
const
port
=
app
.
get
(
'port'
);
server
.
listen
(
port
);
server
.
on
(
'error'
,
onError
.
bind
(
port
));
server
.
on
(
'listening'
,
onListening
.
bind
(
port
));
}
function
onError
(
error
)
{
if
(
error
.
syscall
!==
'listen'
)
{
throw
error
;
}
var
bind
=
typeof
this
===
'string'
?
'Pipe '
+
this
:
'Port '
+
this
;
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
;
}
}
function
onListening
()
{
exec
(
'open http://localhost:'
+
this
);
}
function
init
()
{
httpListen
(
configureApp
(
normalizedPort
()));
}
module
.
exports
.
init
=
init
;
bin/loaf
View file @
0a549d09
#!/usr/bin/env node
/**
* Module dependencies.
*/
const
app
=
require
(
'../app'
);
const
debug
=
require
(
'debug'
)(
'loafer:server'
);
const
http
=
require
(
'http'
);
const
exec
=
require
(
'child_process'
).
exec
;
const
express
=
require
(
'express'
);
const
path
=
require
(
'path'
);
const
favicon
=
require
(
'serve-favicon'
);
const
logger
=
require
(
'morgan'
);
const
cookieParser
=
require
(
'cookie-parser'
);
const
bodyParser
=
require
(
'body-parser'
);
const
routes
=
require
(
'../routes/index'
);
const
app
=
express
();
/**
* Get port and normalize into a number, string, or false.
*/
function
normalizedPort
()
{
const
val
=
process
.
env
.
PORT
||
'3011'
;
const
port
=
parseInt
(
val
,
10
);
if
(
isNaN
(
port
))
{
// named pipe
return
val
;
}
if
(
port
>=
0
)
{
// port number
return
port
;
}
return
false
;
}
function
configureApp
(
port
)
{
app
.
set
(
'port'
,
port
);
app
.
set
(
'views'
,
path
.
join
(
__dirname
,
'/../views'
));
app
.
set
(
'view engine'
,
'pug'
);
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app
.
use
(
logger
(
'dev'
));
app
.
use
(
bodyParser
.
json
());
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}));
app
.
use
(
cookieParser
());
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'/../public'
)));
app
.
use
(
'/'
,
routes
);
// catch 404 and forward to error handler
app
.
use
(
function
(
req
,
res
,
next
)
{
const
err
=
new
Error
(
'Not Found'
);
err
.
status
=
404
;
next
(
err
);
});
// development error handler
// will print stacktrace
if
(
app
.
get
(
'env'
)
===
'development'
)
{
app
.
use
(
function
(
err
,
req
,
res
,
next
)
{
res
.
status
(
err
.
status
||
500
);
res
.
render
(
'error'
,
{
message
:
err
.
message
,
error
:
err
});
});
}
// production error handler
// no stacktraces leaked to user
app
.
use
(
function
(
err
,
req
,
res
,
next
)
{
res
.
status
(
err
.
status
||
500
);
res
.
render
(
'error'
,
{
message
:
err
.
message
,
error
:
{}
});
});
return
app
;
}
function
httpListen
(
app
)
{
const
server
=
http
.
createServer
(
app
);
const
port
=
app
.
get
(
'port'
);
server
.
listen
(
port
);
server
.
on
(
'error'
,
onError
.
bind
(
port
));
server
.
on
(
'listening'
,
onListening
.
bind
(
port
));
}
function
onError
(
error
)
{
if
(
error
.
syscall
!==
'listen'
)
{
throw
error
;
}
var
bind
=
typeof
this
===
'string'
?
'Pipe '
+
this
:
'Port '
+
this
;
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
;
}
}
function
onListening
()
{
exec
(
'open http://localhost:'
+
this
);
}
httpListen
(
configureApp
(
normalizedPort
()));
app
.
init
();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment