[add] 環境

This commit is contained in:
建喵 2023-09-11 15:58:59 +08:00
parent c24174ceb5
commit df3970d8b0
3 changed files with 31 additions and 6 deletions

View File

@ -31,6 +31,7 @@
"dependencies": {
"dayjs": "^1.11.9",
"dotenv": "^16.3.1",
"fs": "^0.0.1-security",
"tsrpc": "^3.4.12"
}
}

View File

@ -1,6 +1,7 @@
import dayjs from "dayjs";
import "dayjs/locale/zh-tw";
import dotenv from "dotenv";
import fs from "fs";
import * as path from "path";
import { BaseConnection, WsServer } from "tsrpc";
import Lobby from "./component/Lobby/Lobby";
@ -15,13 +16,31 @@ BaseEnumerator.Init();
dayjs.locale("zh-tw");
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
const port: number = +process.env.PORT || 3003;
export const server: WsServer<ServiceType> = new WsServer(serviceProto, {
port: port,
// Remove this to use binary mode (remove from the client too)
json: true
});
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,
// Remove this to use binary mode (remove from the client too)
json: true
});
}
// Initialize before server start
async function init() {

View File

@ -795,6 +795,11 @@ fs.realpath@^1.0.0:
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
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:
version "2.3.3"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6"