gateway
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
import type { structure } from "../apiStructure/sammoAPI.js";
|
||||||
|
import type { APINamespaceType } from "./defs.js";
|
||||||
|
|
||||||
|
export const sammoAPI = {
|
||||||
|
} satisfies APINamespaceType<typeof structure>;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { type DefAPINamespace, GET, POST } from "./defs.js";
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
export const structure = {
|
||||||
|
|
||||||
|
} satisfies DefAPINamespace;
|
||||||
Vendored
+22
-7
@@ -1,13 +1,28 @@
|
|||||||
declare namespace NodeJS {
|
declare namespace NodeJS {
|
||||||
interface ProcessEnv {
|
interface ProcessEnv {
|
||||||
NODE_ENV: 'development' | 'production';
|
NODE_ENV: 'development' | 'production';
|
||||||
GAME_DB_HOST: string;
|
|
||||||
GAME_DB_DATABASE: string;
|
//Docker 환경이라면 GAME_DB 또는 GATEWAY_DB 둘중에 하나만 설정되어 있을 것이다.
|
||||||
GAME_DB_PORT: string;
|
GAME_DB_HOST?: string;
|
||||||
GAME_DB_USER: string;
|
GAME_DB_DATABASE?: string;
|
||||||
GAME_DB_PASSWORD: string;
|
GAME_DB_PORT?: string;
|
||||||
SERVER_PORT: string; //숫자
|
GAME_DB_USER?: string;
|
||||||
SESSION_SECRET: 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;
|
API_ROOT_PATH?: string;
|
||||||
VITE_API_ROOT_PATH?: string;
|
VITE_API_ROOT_PATH?: string;
|
||||||
|
|||||||
@@ -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 {};
|
||||||
@@ -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
@@ -1,20 +1,14 @@
|
|||||||
import 'dotenv/config';
|
|
||||||
import 'reflect-metadata';
|
import 'reflect-metadata';
|
||||||
import express, { type Request, type Response } from "express"
|
import express, { type Request, type Response } from "express"
|
||||||
import session from "express-session";
|
import session from "express-session";
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { LiteHashDRBG } from './util/LiteHashDRBG.js';
|
import { LiteHashDRBG } from './util/LiteHashDRBG.js';
|
||||||
import { simpleSerialize } from './util/simpleSerialize.js';
|
import { simpleSerialize } from './util/simpleSerialize.js';
|
||||||
import { SammoRootAPI } from './clientAPI/sammoRootAPI.js';
|
|
||||||
import { buildAPISystem } from './api/generator.js';
|
import { buildAPISystem } from './api/generator.js';
|
||||||
import { sammoRootAPI } from './api/root.js';
|
|
||||||
import { unwrap } from './util/unwrap.js';
|
import { unwrap } from './util/unwrap.js';
|
||||||
|
import { sammoAPI } from './api/api.js';
|
||||||
const ownConfig = {
|
import { ownConfig } from './serverConfig.js';
|
||||||
sessionSecret: process.env.SESSION_SECRET,
|
|
||||||
port: Number(process.env.SERVER_PORT),
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
// create express app
|
// create express app
|
||||||
@@ -27,7 +21,7 @@ const ownConfig = {
|
|||||||
}))
|
}))
|
||||||
//app.set('etag', false);
|
//app.set('etag', false);
|
||||||
|
|
||||||
app.use('/rootAPI', buildAPISystem(sammoRootAPI));
|
app.use('/api', buildAPISystem(sammoAPI));
|
||||||
|
|
||||||
// start express server
|
// start express server
|
||||||
app.listen(ownConfig.port)
|
app.listen(ownConfig.port)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export const LoginToken = new Schema<ILoginToken>({
|
|||||||
ip: { type: String, required: true },
|
ip: { type: String, required: true },
|
||||||
regDate: { type: Date, required: true },
|
regDate: { type: Date, required: true },
|
||||||
validUntil: { type: Date, required: true },
|
validUntil: { type: Date, required: true },
|
||||||
}, { autoIndex: false })
|
}, { autoIndex: false, autoCreate: false, })
|
||||||
.index({ userID: 1, token: 1 })
|
.index({ userID: 1, token: 1 })
|
||||||
.index({ validUntil: 1 }, { expireAfterSeconds: 1 })
|
.index({ validUntil: 1 }, { expireAfterSeconds: 1 })
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export const ServerConfig = new Schema<IServerConfig>({
|
|||||||
allowRegister: { type: Boolean, required: true },
|
allowRegister: { type: Boolean, required: true },
|
||||||
}, {
|
}, {
|
||||||
autoIndex: false,
|
autoIndex: false,
|
||||||
|
autoCreate: false,
|
||||||
capped: {
|
capped: {
|
||||||
max: 1,
|
max: 1,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export const ServerVersion = new Schema<IServerVersion>({
|
|||||||
branch: { type: String, required: true },
|
branch: { type: String, required: true },
|
||||||
version: { type: String, required: true },
|
version: { type: String, required: true },
|
||||||
updateDate: { type: Date, required: true },
|
updateDate: { type: Date, required: true },
|
||||||
}, { autoIndex: false })
|
}, { autoIndex: false, autoCreate: false, })
|
||||||
.index({ serverKey: 1 }, { unique: true })
|
.index({ serverKey: 1 }, { unique: true })
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ export const User = new Schema<IUser>({
|
|||||||
|
|
||||||
regDate: { type: Date, required: true },
|
regDate: { type: Date, required: true },
|
||||||
deleteAfter: { type: Date, required: false },
|
deleteAfter: { type: Date, required: false },
|
||||||
}, { autoIndex: false })
|
}, { autoIndex: false, autoCreate: false })
|
||||||
.index({ id: 1 }, { unique: true })
|
.index({ id: 1 }, { unique: true })
|
||||||
.index({ email: 1 }, { unique: true })
|
.index({ email: 1 }, { unique: true })
|
||||||
.index({ oauthID: 1 }, { unique: true, sparse: true })
|
.index({ oauthID: 1 }, { unique: true, sparse: true })
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export const UserLog = new Schema<IUserLog>({
|
|||||||
logDate: { type: Date, required: true },
|
logDate: { type: Date, required: true },
|
||||||
logType: { type: String, required: true, enum: LogTypeList },
|
logType: { type: String, required: true, enum: LogTypeList },
|
||||||
action: { type: Object, required: true },
|
action: { type: Object, required: true },
|
||||||
}, { autoIndex: false })
|
}, { autoIndex: false, autoCreate: false, })
|
||||||
.index({ userID: 1, logDate: 1 })
|
.index({ userID: 1, logDate: 1 })
|
||||||
.index({ logDate: 1 }, { expireAfterSeconds: 60 * 60 * 24 * 365 * 3 })
|
.index({ logDate: 1 }, { expireAfterSeconds: 60 * 60 * 24 * 365 * 3 })
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -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)),
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user