Skip to content

Commit ac8e475

Browse files
committed
fix: bin/www - 이거 지우지 마세요!!
1 parent 349ba15 commit ac8e475

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

bin/www

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var app = require('../app');
8+
var debug = require('debug')('cheatsol-be:server');
9+
var http = require('http');
10+
11+
/**
12+
* Get port from environment and store in Express.
13+
*/
14+
15+
var port = normalizePort(process.env.PORT || '3000');
16+
app.set('port', port);
17+
18+
/**
19+
* Create HTTP server.
20+
*/
21+
22+
var server = http.createServer(app);
23+
24+
/**
25+
* Listen on provided port, on all network interfaces.
26+
*/
27+
28+
server.listen(port, ()=>{
29+
console.log(`
30+
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
31+
┃ Server listening on port: ${port}
32+
┃ http://localhost:${port}/ ┃
33+
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
34+
`)
35+
});
36+
server.on('error', onError);
37+
server.on('listening', onListening);
38+
39+
/**
40+
* Normalize a port into a number, string, or false.
41+
*/
42+
43+
function normalizePort(val) {
44+
var port = parseInt(val, 10);
45+
46+
if (isNaN(port)) {
47+
// named pipe
48+
return val;
49+
}
50+
51+
if (port >= 0) {
52+
// port number
53+
return port;
54+
}
55+
56+
return false;
57+
}
58+
59+
/**
60+
* Event listener for HTTP server "error" event.
61+
*/
62+
63+
function onError(error) {
64+
if (error.syscall !== 'listen') {
65+
throw error;
66+
}
67+
68+
var bind = typeof port === 'string'
69+
? 'Pipe ' + port
70+
: 'Port ' + port;
71+
72+
// handle specific listen errors with friendly messages
73+
switch (error.code) {
74+
case 'EACCES':
75+
console.error(bind + ' requires elevated privileges');
76+
process.exit(1);
77+
break;
78+
case 'EADDRINUSE':
79+
console.error(bind + ' is already in use');
80+
process.exit(1);
81+
break;
82+
default:
83+
throw error;
84+
}
85+
}
86+
87+
/**
88+
* Event listener for HTTP server "listening" event.
89+
*/
90+
91+
function onListening() {
92+
var addr = server.address();
93+
var bind = typeof addr === 'string'
94+
? 'pipe ' + addr
95+
: 'port ' + addr.port;
96+
debug('Listening on ' + bind);
97+
}

0 commit comments

Comments
 (0)