[add] 環境
This commit is contained in:
parent
c24174ceb5
commit
df3970d8b0
@ -31,6 +31,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dayjs": "^1.11.9",
|
"dayjs": "^1.11.9",
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
|
"fs": "^0.0.1-security",
|
||||||
"tsrpc": "^3.4.12"
|
"tsrpc": "^3.4.12"
|
||||||
}
|
}
|
||||||
}
|
}
|
21
src/index.ts
21
src/index.ts
@ -1,6 +1,7 @@
|
|||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import "dayjs/locale/zh-tw";
|
import "dayjs/locale/zh-tw";
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
|
import fs from "fs";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { BaseConnection, WsServer } from "tsrpc";
|
import { BaseConnection, WsServer } from "tsrpc";
|
||||||
import Lobby from "./component/Lobby/Lobby";
|
import Lobby from "./component/Lobby/Lobby";
|
||||||
@ -15,13 +16,31 @@ BaseEnumerator.Init();
|
|||||||
dayjs.locale("zh-tw");
|
dayjs.locale("zh-tw");
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
|
const prikey: string = fs.readFileSync("./certificate/RSA-privkey.pem", "utf8");
|
||||||
|
const cert: string = fs.readFileSync("./certificate/RSA-cert.pem", "utf8");
|
||||||
|
|
||||||
// Create the Server
|
// Create the Server
|
||||||
const port: number = +process.env.PORT || 3003;
|
const port: number = +process.env.PORT || 3003;
|
||||||
export const server: WsServer<ServiceType> = new WsServer(serviceProto, {
|
export let server: WsServer<ServiceType> = undefined;
|
||||||
|
console.log(`NODE_ENV ${process.env.NODE_ENV}`);
|
||||||
|
if (process.env.NODE_ENV === "prod") {
|
||||||
|
server = new WsServer(serviceProto, {
|
||||||
|
port: port,
|
||||||
|
// Remove this to use binary mode (remove from the client too)
|
||||||
|
json: true,
|
||||||
|
// 启用 WSS
|
||||||
|
wss: {
|
||||||
|
key: prikey,
|
||||||
|
cert: cert
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
server = new WsServer(serviceProto, {
|
||||||
port: port,
|
port: port,
|
||||||
// Remove this to use binary mode (remove from the client too)
|
// Remove this to use binary mode (remove from the client too)
|
||||||
json: true
|
json: true
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize before server start
|
// Initialize before server start
|
||||||
async function init() {
|
async function init() {
|
||||||
|
@ -795,6 +795,11 @@ fs.realpath@^1.0.0:
|
|||||||
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
|
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
|
||||||
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==
|
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==
|
||||||
|
|
||||||
|
fs@^0.0.1-security:
|
||||||
|
version "0.0.1-security"
|
||||||
|
resolved "https://registry.yarnpkg.com/fs/-/fs-0.0.1-security.tgz#8a7bd37186b6dddf3813f23858b57ecaaf5e41d4"
|
||||||
|
integrity sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==
|
||||||
|
|
||||||
fsevents@~2.3.2:
|
fsevents@~2.3.2:
|
||||||
version "2.3.3"
|
version "2.3.3"
|
||||||
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6"
|
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6"
|
||||||
|
Loading…
Reference in New Issue
Block a user