Toggle navigation
Toggle navigation
This project
Loading...
Sign in
강동현
/
nodejs-game
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
강동현
2021-06-10 23:13:18 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
88e1d78060888b9ab593d36e60b62886df468ee9
88e1d780
1 parent
4d493af3
개발 환경에 맞게 서버 설정 조정
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
3 deletions
server/Dockerfile
server/Server.ts
server/index.ts
web/src/contexts/SocketContext.ts
server/Dockerfile
View file @
88e1d78
...
...
@@ -18,4 +18,6 @@ RUN yarn build
EXPOSE
3000
ENV
NODE_ENV production
CMD
[ "node", "dist/server/index.js" ]
...
...
server/Server.ts
View file @
88e1d78
import
express
from
"express"
;
import
socketIo
,
{
Server
as
IoServer
}
from
"socket.io"
;
import
{
createServer
}
from
"https"
;
import
{
createServer
as
createServerHttps
}
from
"https"
;
import
{
createServer
as
createServerHttp
}
from
"http"
;
import
{
RoomManager
}
from
"./room/RoomManager"
;
import
{
Connection
}
from
"./connection/Connection"
;
import
{
SocketIoWrapper
}
from
"./connection/SocketWrapper"
;
...
...
@@ -13,8 +14,14 @@ export class Server {
constructor
(
port
:
number
)
{
this
.
port
=
port
;
console
.
log
(
`Running in
${
process
.
env
.
NODE_ENV
}
mode.`
);
const
app
=
express
();
const
server
=
createServer
(
let
server
;
if
(
process
.
env
.
NODE_ENV
===
"development"
)
{
server
=
createServerHttp
(
app
);
}
else
{
server
=
createServerHttps
(
{
cert
:
readFileSync
(
"/etc/letsencrypt/live/2020105578.oss2021.tk/cert.pem"
...
...
@@ -28,6 +35,7 @@ export class Server {
},
app
);
}
this
.
io
=
new
socketIo
.
Server
(
server
,
{
cors
:
{
origin
:
"*"
,
...
...
server/index.ts
View file @
88e1d78
import
{
Server
}
from
"./Server"
;
process
.
env
.
NODE_ENV
=
process
.
env
.
NODE_ENV
&&
process
.
env
.
NODE_ENV
.
trim
().
toLowerCase
()
==
"production"
?
"production"
:
"development"
;
new
Server
(
3000
);
...
...
web/src/contexts/SocketContext.ts
View file @
88e1d78
import
React
from
"react"
;
import
{
io
}
from
"socket.io-client"
;
export
const
socket
=
io
(
`https://
${
window
.
location
.
hostname
}
:3000/`
);
export
const
socket
=
io
(
`
${
window
.
location
.
protocol
}
//
${
window
.
location
.
hostname
}
:3000/`
);
const
SocketContext
=
React
.
createContext
(
socket
);
export
const
SocketProvider
=
SocketContext
.
Provider
;
...
...
Please
register
or
login
to post a comment