From 69de10642e7c3183eeec8743982033dfb03b00f4 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sun, 6 Aug 2023 13:53:12 +0000 Subject: [PATCH] =?UTF-8?q?express.js=20=EC=A4=80=EB=B9=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/Login/LoginByID.ts | 4 ++-- server/api/defs.ts | 24 +++++++++++------------- server/clientAPI/sammoRootAPI.ts | 2 +- server/index.ts | 26 ++++++-------------------- 4 files changed, 20 insertions(+), 36 deletions(-) diff --git a/server/api/Login/LoginByID.ts b/server/api/Login/LoginByID.ts index 9b741af..009443a 100644 --- a/server/api/Login/LoginByID.ts +++ b/server/api/Login/LoginByID.ts @@ -8,8 +8,8 @@ type EType = ExtractError; type QType = ExtractQuery; class Q implements QType { - username: string; - password: string; + username!: string; + password!: string; } export class LoginByID extends POST{ readonly argValidator = undefined; diff --git a/server/api/defs.ts b/server/api/defs.ts index 042f451..58317d1 100644 --- a/server/api/defs.ts +++ b/server/api/defs.ts @@ -3,20 +3,18 @@ import type { Request, Response } from 'express'; import type { Callable, DefAPINamespace, DeleteAPICallT, GetAPICallT, HeadAPICallT, HttpMethod, InvalidResponse, PatchAPICallT, PostAPICallT, PutAPICallT, RawArgType, ValidResponse, recoveryMethod } from '../apiStructure/defs'; import { validate, - validateSync, - validateOrReject, - ValidatorOptions, - } from "class-validator"; -import { ClassTransformOptions, plainToInstance } from "class-transformer"; + type ValidatorOptions, +} from "class-validator"; +import { type ClassTransformOptions, plainToInstance } from "class-transformer"; export type APINamespace = { [key: string]: APINamespace - | GET - | POST - | PUT - | DELETE - | PATCH - | HEAD + | ClassType> + | ClassType> + | ClassType> + | ClassType> + | ClassType> + | ClassType> ; } @@ -41,7 +39,7 @@ export abstract class APIExecuter extends APIExecuter{ protected async parseQuery(expressReq: Request): Promise { - if(!this.argValidator){ + if (!this.argValidator) { return expressReq.body as Q; } @@ -59,7 +57,7 @@ export abstract class APIBodyParseExecuter extends APIExecuter{ override readonly reqType = 'get'; protected async parseQuery(expressReq: Request): Promise { - if(!this.argValidator){ + if (!this.argValidator) { return expressReq.query as Q; } diff --git a/server/clientAPI/sammoRootAPI.ts b/server/clientAPI/sammoRootAPI.ts index 16836e7..6498247 100644 --- a/server/clientAPI/sammoRootAPI.ts +++ b/server/clientAPI/sammoRootAPI.ts @@ -3,7 +3,7 @@ import type { APITail, RawArgType } from "../apiStructure/defs"; import { structure } from "../apiStructure/sammoRootAPI"; import { callClientAPI } from "./generator"; -const apiRoot = process.env.API_ROOT_PATH ?? process.env.VITE_API_ROOT_PATH ?? '/api'; +const apiRoot = process.env.API_ROOT_PATH ?? process.env.VITE_API_ROOT_PATH ?? '/rootAPI'; export const SammoRootAPI = APIPathGen(structure, (path: string[], tail: APITail, pathParam) => { const method = tail.reqType; diff --git a/server/index.ts b/server/index.ts index d5161a0..1800625 100644 --- a/server/index.ts +++ b/server/index.ts @@ -8,29 +8,15 @@ import path from 'node:path'; import { LiteHashDRBG } from './util/LiteHashDRBG.js'; import { simpleSerialize } from './util/simpleSerialize.js'; import { SammoRootAPI } from './clientAPI/sammoRootAPI.js'; - -export async function test() { - console.log("Hello World!"); - console.log(process.env.GAME_DB_HOST); - - const abc= { - a: 1, - b: 2, - c: 3, - } - const t2 = await validate(abc); - console.log(t2); -} - - -await test(); +import { buildAPISystem } from './api/generator.js'; +import { sammoRootAPI } from './api/root.js'; const ownConfig = { sessionSecret: process.env.SESSION_SECRET, port: Number(process.env.SERVER_PORT), } -/* + AppDataSource.initialize().then(async () => { // create express app const app = express() @@ -40,9 +26,9 @@ AppDataSource.initialize().then(async () => { resave: false, saveUninitialized: false, })) - app.set('etag', false); + //app.set('etag', false); - //app.use('/', rootRouter); + app.use('/rootAPI', buildAPISystem(sammoRootAPI)); // start express server app.listen(ownConfig.port) @@ -50,5 +36,5 @@ AppDataSource.initialize().then(async () => { console.log(`Express server has started on port ${ownConfig.port}`) }).catch(error => console.log(error)) -*/ + export default {}; \ No newline at end of file