wip
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import 'dotenv/config';
|
||||
import { connect, Mongoose } from "mongoose";
|
||||
import { unwrap } from './util/unwrap.js';
|
||||
|
||||
const dbConfig = {
|
||||
host: unwrap(process.env.GAME_DB_HOST),
|
||||
port: Number(unwrap(process.env.GAME_DB_PORT)),
|
||||
user: unwrap(process.env.GAME_DB_USER),
|
||||
password: unwrap(process.env.GAME_DB_PASSWORD),
|
||||
database: unwrap(process.env.GAME_DB_DATABASE),
|
||||
}
|
||||
|
||||
const db: Promise<Mongoose> = (async () => {
|
||||
return await connect(`mongodb://${dbConfig.host}:${dbConfig.port}/${dbConfig.database}`, {
|
||||
auth:{
|
||||
username: dbConfig.user,
|
||||
password: dbConfig.password,
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
export default db;
|
||||
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
declare namespace NodeJS {
|
||||
interface ProcessEnv {
|
||||
NODE_ENV: 'development' | 'production';
|
||||
|
||||
//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;
|
||||
|
||||
PRESHARED_SECURE_TOKEN_SECRET?: string; //길게
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import 'reflect-metadata';
|
||||
import connectDB from './connectDB.js';
|
||||
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 { buildAPISystem } from './api/generator.js';
|
||||
import { unwrap } from './util/unwrap.js';
|
||||
import { sammoAPI } from './api/api.js';
|
||||
import { ownConfig } from './serverConfig.js';
|
||||
|
||||
connectDB.then(async (db) => {
|
||||
// create express app
|
||||
const app = express()
|
||||
app.use(express.json());
|
||||
app.use(session({
|
||||
secret: unwrap(ownConfig.sessionSecret),
|
||||
resave: false,
|
||||
saveUninitialized: false,
|
||||
}))
|
||||
//app.set('etag', false);
|
||||
|
||||
app.use('/api', buildAPISystem(sammoAPI));
|
||||
|
||||
// start express server
|
||||
app.listen(ownConfig.port)
|
||||
|
||||
console.log(`Express server has started on port ${ownConfig.port}`)
|
||||
|
||||
}).catch(error => console.log(error));
|
||||
|
||||
export default {};
|
||||
@@ -0,0 +1,35 @@
|
||||
import type { LoginCtx } from "./ReqLogin.js";
|
||||
import type { SessionCtx } from "./StartSession.js";
|
||||
import type { ProcDecoratorGenerator } from "./base.js";
|
||||
|
||||
export type GameLoginCtx = {
|
||||
generalID: number;
|
||||
generalName: string;
|
||||
gameLoginDate: Date;
|
||||
}
|
||||
|
||||
export function ReqGameLogin<Q extends LoginCtx & SessionCtx>(): ProcDecoratorGenerator<GameLoginCtx, Q> {
|
||||
return async (ctx) => {
|
||||
//NOTE: 게임 서버별로 gameLoginCtx를 따로 가져야 하는가?
|
||||
let gameLoginCtx = ctx.session.getItem<GameLoginCtx>(`gameLoginCtx`);
|
||||
if(gameLoginCtx){
|
||||
if(gameLoginCtx.gameLoginDate >= ctx.loginDate){
|
||||
return [{
|
||||
result: true,
|
||||
},{
|
||||
...gameLoginCtx,
|
||||
...ctx,
|
||||
}];
|
||||
}
|
||||
gameLoginCtx = undefined;
|
||||
}
|
||||
|
||||
//TODO: DB에서 generalID를 가져오는 로직
|
||||
|
||||
return [{
|
||||
result: false,
|
||||
type: 'Required GameLogin',
|
||||
info: 'NotYetImplemented'
|
||||
}, ctx];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import type { ServerActionType } from "../schema/gateway/User.js";
|
||||
import type { SessionCtx } from "./StartSession.js";
|
||||
import type { ProcDecorator } from "./base.js";
|
||||
|
||||
export type LoginCtx = {
|
||||
userID: number;
|
||||
userName: string;
|
||||
userLevel: number;
|
||||
allowServerAction?: Set<ServerActionType>;
|
||||
loginDate: Date;
|
||||
}
|
||||
export const loginCtxSessionKey = 'loginCtx';
|
||||
|
||||
export function ReqLogin<Q extends SessionCtx>(): ProcDecorator<LoginCtx & Q, Q> {
|
||||
return (ctx) => {
|
||||
const loginCtx = ctx.session.getItem<LoginCtx>(loginCtxSessionKey);
|
||||
if(!loginCtx){
|
||||
return [{
|
||||
result: false,
|
||||
type: 'Required Login',
|
||||
info: 'ReqLogin'
|
||||
}, ctx];
|
||||
}
|
||||
|
||||
return [{
|
||||
result: true,
|
||||
},{
|
||||
...loginCtx,
|
||||
...ctx,
|
||||
}];
|
||||
}
|
||||
}
|
||||
@@ -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