This commit is contained in:
2023-08-18 15:47:10 +00:00
parent 60848987eb
commit 199938f2b2
12 changed files with 95 additions and 21 deletions
+5
View File
@@ -0,0 +1,5 @@
import type { structure } from "../apiStructure/sammoAPI.js";
import type { APINamespaceType } from "./defs.js";
export const sammoAPI = {
} satisfies APINamespaceType<typeof structure>;
+6
View File
@@ -0,0 +1,6 @@
import { type DefAPINamespace, GET, POST } from "./defs.js";
/** @internal */
export const structure = {
} satisfies DefAPINamespace;
+22 -7
View File
@@ -1,13 +1,28 @@
declare namespace NodeJS {
interface ProcessEnv {
NODE_ENV: 'development' | 'production';
GAME_DB_HOST: string;
GAME_DB_DATABASE: string;
GAME_DB_PORT: string;
GAME_DB_USER: string;
GAME_DB_PASSWORD: string;
SERVER_PORT: string; //숫자
SESSION_SECRET: string; //길게
//Docker 환경이라면 GAME_DB 또는 GATEWAY_DB 둘중에 하나만 설정되어 있을 것이다.
GAME_DB_HOST?: string;
GAME_DB_DATABASE?: string;
GAME_DB_PORT?: string;
GAME_DB_USER?: string;
GAME_DB_PASSWORD?: string;
GATEWAY_DB_HOST?: string;
GATEWAY_DB_DATABASE?: string;
GATEWAY_DB_PORT?: string;
GATEWAY_DB_USER?: string;
GATEWAY_DB_PASSWORD?: string;
//Gateway RPC용
GATEWAY_HOST?: string;
GATEWAY_PORT?: string;
//gateway.ts용
GATEWAY_SESSION_SECRET?: string;
SERVER_PORT?: string; //숫자
SESSION_SECRET?: string; //길게
API_ROOT_PATH?: string;
VITE_API_ROOT_PATH?: string;
+37
View File
@@ -0,0 +1,37 @@
import 'dotenv/config';
import 'reflect-metadata';
import express, { type Request, type Response } from "express"
import session from "express-session";
import path from 'node:path';
import { LiteHashDRBG } from './util/LiteHashDRBG.js';
import { simpleSerialize } from './util/simpleSerialize.js';
import { SammoRootAPI } from './clientAPI/sammoRootAPI.js';
import { buildAPISystem } from './api/generator.js';
import { sammoRootAPI } from './api/root.js';
import { unwrap } from './util/unwrap.js';
import { gatewayConfig } from './gatewayConfig.js';
(async () => {
// create express app
const app = express()
app.use(express.json());
app.use(session({
secret: unwrap(gatewayConfig.sessionSecret),
resave: false,
saveUninitialized: false,
}))
//app.set('etag', false);
app.use('/gateway_api', buildAPISystem(sammoRootAPI));
// start express server
app.listen(gatewayConfig.port)
console.log(`Gateway server has started on port ${gatewayConfig.port}`)
})().catch(error => console.log(error));
export default {};
+7
View File
@@ -0,0 +1,7 @@
import 'dotenv/config';
import { unwrap } from './util/unwrap.js';
export const gatewayConfig = {
sessionSecret: unwrap(process.env.GATEWAY_SESSION_SECRET),
port: Number(unwrap(process.env.GATEWAY_PORT)),
};
+4 -10
View File
@@ -1,20 +1,14 @@
import 'dotenv/config';
import 'reflect-metadata';
import express, { type Request, type Response } from "express"
import session from "express-session";
import path from 'node:path';
import { LiteHashDRBG } from './util/LiteHashDRBG.js';
import { simpleSerialize } from './util/simpleSerialize.js';
import { SammoRootAPI } from './clientAPI/sammoRootAPI.js';
import { buildAPISystem } from './api/generator.js';
import { sammoRootAPI } from './api/root.js';
import { unwrap } from './util/unwrap.js';
const ownConfig = {
sessionSecret: process.env.SESSION_SECRET,
port: Number(process.env.SERVER_PORT),
};
import { sammoAPI } from './api/api.js';
import { ownConfig } from './serverConfig.js';
(async () => {
// create express app
@@ -27,7 +21,7 @@ const ownConfig = {
}))
//app.set('etag', false);
app.use('/rootAPI', buildAPISystem(sammoRootAPI));
app.use('/api', buildAPISystem(sammoAPI));
// start express server
app.listen(ownConfig.port)
+1 -1
View File
@@ -15,7 +15,7 @@ export const LoginToken = new Schema<ILoginToken>({
ip: { type: String, required: true },
regDate: { type: Date, required: true },
validUntil: { type: Date, required: true },
}, { autoIndex: false })
}, { autoIndex: false, autoCreate: false, })
.index({ userID: 1, token: 1 })
.index({ validUntil: 1 }, { expireAfterSeconds: 1 })
;
+1
View File
@@ -12,6 +12,7 @@ export const ServerConfig = new Schema<IServerConfig>({
allowRegister: { type: Boolean, required: true },
}, {
autoIndex: false,
autoCreate: false,
capped: {
max: 1,
}
+1 -1
View File
@@ -12,7 +12,7 @@ export const ServerVersion = new Schema<IServerVersion>({
branch: { type: String, required: true },
version: { type: String, required: true },
updateDate: { type: Date, required: true },
}, { autoIndex: false })
}, { autoIndex: false, autoCreate: false, })
.index({ serverKey: 1 }, { unique: true })
;
+1 -1
View File
@@ -80,7 +80,7 @@ export const User = new Schema<IUser>({
regDate: { type: Date, required: true },
deleteAfter: { type: Date, required: false },
}, { autoIndex: false })
}, { autoIndex: false, autoCreate: false })
.index({ id: 1 }, { unique: true })
.index({ email: 1 }, { unique: true })
.index({ oauthID: 1 }, { unique: true, sparse: true })
+1 -1
View File
@@ -22,7 +22,7 @@ export const UserLog = new Schema<IUserLog>({
logDate: { type: Date, required: true },
logType: { type: String, required: true, enum: LogTypeList },
action: { type: Object, required: true },
}, { autoIndex: false })
}, { autoIndex: false, autoCreate: false, })
.index({ userID: 1, logDate: 1 })
.index({ logDate: 1 }, { expireAfterSeconds: 60 * 60 * 24 * 365 * 3 })
;
+9
View File
@@ -0,0 +1,9 @@
import 'dotenv/config';
import { unwrap } from './util/unwrap.js';
export const ownConfig = {
sessionSecret: unwrap(process.env.SESSION_SECRET),
port: Number(unwrap(process.env.SERVER_PORT)),
gatewayHost: unwrap(process.env.GATEWAY_HOST),
gatewayPort: Number(unwrap(process.env.GATEWAY_PORT)),
};