This commit is contained in:
2023-09-23 16:24:32 +00:00
parent ffd3ab681e
commit bfbc0134de
31 changed files with 304 additions and 181 deletions
+11 -1
View File
@@ -15,13 +15,23 @@
"license": "MIT",
"dependencies": {
"@sammo/api_def": "workspace:^",
"@sammo/crypto": "workspace:^",
"@sammo/server_util": "workspace:^",
"@sammo/util": "workspace:^",
"@strpc/express": "workspace:^",
"date-fns": "^2.30.0",
"dotenv": "^16.3.1",
"mongoose": "^7.4.3"
"express": "^4.18.2",
"express-session": "^1.17.3",
"lodash-es": "^4.17.21",
"mongoose": "^7.4.3",
"reflect-metadata": "^0.1.13",
"tslib": "^2.6.2",
"zod": "^3.22.2"
},
"devDependencies": {
"@types/express": "^4.17.17",
"@types/express-session": "^1.17.7",
"@types/node": "^20.6.3"
}
}
@@ -47,7 +47,8 @@ export const LoginByID = POST<BaseAPI>(LoginByIDReq)(declProcDecorators(
userID,
userName,
userLevel,
allowServerAction: new Set(),
allowServerAction: new Map(),
allowGatewayAction: new Set(),
loginDate: new Date(),
}
@@ -3,7 +3,8 @@ import { StartSession } from "@sammo/server_util";
import { POST, type APIReturnType } from "@strpc/express";
import { declProcDecorators } from "@strpc/express/proc_decorator";
import { z } from "zod";
import { loginCtxSessionKey, type GatewayLoginCtx } from "../../procDecorator/ReqGatewayLogin.js";
import { loginCtxSessionKey, type GatewayLoginCtx } from "@/procDecorator/ReqGatewayLogin.js";
import { delay } from "@sammo/util";
type BaseAPI = typeof structure.Login.LoginByToken;
type RType = APIReturnType<BaseAPI>;
@@ -16,7 +17,7 @@ const LoginByTokenReq = z.object({
export const LoginByToken = POST<BaseAPI>(LoginByTokenReq)(declProcDecorators(
StartSession,
))
(async (query, ctx) => {
(async (query, ctx): RType => {
query.hashedToken;
ctx.session.clear();
@@ -33,6 +34,7 @@ export const LoginByToken = POST<BaseAPI>(LoginByTokenReq)(declProcDecorators(
userName,
userLevel,
allowServerAction: new Map(),
allowGatewayAction: new Set(),
loginDate: new Date(),
}
@@ -3,11 +3,9 @@ import type { APINamespaceType } from "@strpc/express";
import { LoginByID } from "./LoginByID.js";
import { LoginByToken } from "./LoginByToken.js";
import { ReqNonce } from "./ReqNonce.js";
import { test } from "./test.js";
export const Login = {
LoginByID,
LoginByToken,
ReqNonce,
test,
} satisfies APINamespaceType<typeof structure.Login>;
+1 -1
View File
@@ -31,7 +31,7 @@ function generateConfig() {
return {
port: parseInt(process.env['SERVER_PORT'] ?? "3001"),
sessionSecret: unwrap(process.env['SESSION_SECRET']),
apiRootPath: process.env['API_ROOT_PATH'] ?? '/api/gateway',
apiRootPath: process.env['API_ROOT_PATH'] ?? '/api',
} as const;
}
+2 -2
View File
@@ -2,8 +2,8 @@ export type {
ServerActionType,
UserIDType,
IUser,
} from "./schema/User.ts";
} from "./schema/User.js";
export type {
ILoginToken
} from "./schema/LoginToken.ts";
} from "./schema/LoginToken.js";
@@ -1,7 +0,0 @@
import 'dotenv/config';
import { unwrap } from "@sammo/util";
export const gatewayConfig = {
sessionSecret: unwrap(process.env.GATEWAY_SESSION_SECRET),
port: Number(unwrap(process.env.GATEWAY_PORT)),
};
+5 -5
View File
@@ -1,15 +1,15 @@
import './dotenv.js'
import { ownConfig } from './dotenv.js';
import 'reflect-metadata';
import gatewayDB from './connectDB.js';
import express, { type Request, type Response } from "express"
import session from "express-session";
import { buildAPISystem } from '@strpc/express/generator';
//import { sammoGatewayAPI } from './api/index.js';
import { unwrap } from '@sammo/util';;
import { gatewayConfig } from './gatewayConfig.js';
import { sammoGatewayAPI } from './api/index.js';
import { unwrap } from '@sammo/util';
const gatewayConfig = ownConfig();
gatewayDB.then(async (gatewayDB) => {
// create express app
@@ -22,7 +22,7 @@ gatewayDB.then(async (gatewayDB) => {
}))
//app.set('etag', false);
//app.use('/gateway_api', buildAPISystem(sammoGatewayAPI));
app.use('/gateway_api', buildAPISystem(sammoGatewayAPI));
// start express server
app.listen(gatewayConfig.port)
+6
View File
@@ -3,11 +3,17 @@
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
"paths": {
"@/*": ["./src/*"]
}
},
"references": [
{
"path": "../../@strpc/express"
},
{
"path": "../api_def"
},
{
"path": "../util"
},