add prettier
This commit is contained in:
22
api/package-lock.json
generated
22
api/package-lock.json
generated
@ -21,6 +21,7 @@
|
||||
"@types/express-session": "^1.17.5",
|
||||
"@types/ip": "^1.1.0",
|
||||
"@types/node": "^18.7.18",
|
||||
"prettier": "^2.7.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"ts-node-dev": "^2.0.0",
|
||||
"typescript": "^4.0.0"
|
||||
@ -1124,6 +1125,21 @@
|
||||
"url": "https://github.com/sponsors/jonschlinkert"
|
||||
}
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz",
|
||||
"integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"prettier": "bin-prettier.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.13.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/proxy-addr": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
||||
@ -2508,6 +2524,12 @@
|
||||
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
|
||||
"dev": true
|
||||
},
|
||||
"prettier": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz",
|
||||
"integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==",
|
||||
"dev": true
|
||||
},
|
||||
"proxy-addr": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
||||
|
@ -7,7 +7,8 @@
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"dev": "ts-node-dev --respawn --transpile-only ./src/app.ts",
|
||||
"start": "npm run build && node ./dist/app.js"
|
||||
"start": "npm run build && node ./dist/app.js",
|
||||
"prettier": "prettier -w ./src"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/cors": "^2.8.12",
|
||||
@ -15,6 +16,7 @@
|
||||
"@types/express-session": "^1.17.5",
|
||||
"@types/ip": "^1.1.0",
|
||||
"@types/node": "^18.7.18",
|
||||
"prettier": "^2.7.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"ts-node-dev": "^2.0.0",
|
||||
"typescript": "^4.0.0"
|
||||
|
@ -1,16 +1,18 @@
|
||||
import Server, { Services } from './framework/express/server';
|
||||
import Mongo from './framework/mongo/mongo';
|
||||
import ip from "ip";
|
||||
import ip from 'ip';
|
||||
|
||||
const PORT = 8000;
|
||||
const MONGOURI = "mongodb://localhost:27017";
|
||||
const MONGOURI = 'mongodb://localhost:27017';
|
||||
|
||||
const mongo = new Mongo(MONGOURI);
|
||||
|
||||
const services: Services = {
|
||||
db: mongo.getDb()
|
||||
}
|
||||
db: mongo.getDb(),
|
||||
};
|
||||
|
||||
const server = new Server(services);
|
||||
|
||||
server.start(PORT, () => console.log(`Running on http://${ip.address()}:${PORT}`));
|
||||
server.start(PORT, () =>
|
||||
console.log(`Running on http://${ip.address()}:${PORT}`),
|
||||
);
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { RequestHandler } from "express";
|
||||
import { randomUUID } from "crypto";
|
||||
import { RequestHandler } from 'express';
|
||||
import { randomUUID } from 'crypto';
|
||||
|
||||
export function BeforeEach(): RequestHandler {
|
||||
return (req, res, next) => {
|
||||
req.headers["request-id"] = randomUUID();
|
||||
req.headers['request-id'] = randomUUID();
|
||||
next();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { Router } from "express";
|
||||
import { Services } from "./server";
|
||||
import * as user from "./user";
|
||||
import { Router } from 'express';
|
||||
import { Services } from './server';
|
||||
import * as user from './user';
|
||||
|
||||
export function getRoutes(services: Services) {
|
||||
const router = Router();
|
||||
|
||||
router.use("/user", user.getRoutes(services));
|
||||
router.use('/user', user.getRoutes(services));
|
||||
|
||||
return router;
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import express, { Express } from "express";
|
||||
import express, { Express } from 'express';
|
||||
import cors from 'cors';
|
||||
import * as router from './router';
|
||||
import { BeforeEach } from "./middleware";
|
||||
import { Db } from "mongodb";
|
||||
import { BeforeEach } from './middleware';
|
||||
import { Db } from 'mongodb';
|
||||
|
||||
export type Services = {
|
||||
db: Db;
|
||||
}
|
||||
};
|
||||
|
||||
class Server {
|
||||
private app: Express;
|
||||
|
@ -12,10 +12,10 @@ export function CreateHandler(services: Services): RequestHandler {
|
||||
const createUser = Create(services);
|
||||
|
||||
return async (req, res) => {
|
||||
const user = await createUser(req.get("request-id"), req.body);
|
||||
|
||||
const user = await createUser(req.get('request-id'), req.body);
|
||||
|
||||
res.send(user);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function getRoutes(services: Services) {
|
||||
@ -23,8 +23,6 @@ export function getRoutes(services: Services) {
|
||||
|
||||
router.post('/login', LoginHandler(services));
|
||||
router.post('/create', CreateHandler(services));
|
||||
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { MongoClient, Db } from "mongodb";
|
||||
import { MongoClient, Db } from 'mongodb';
|
||||
|
||||
class Mongo {
|
||||
private client: MongoClient;
|
||||
|
@ -1,14 +1,16 @@
|
||||
import { CreateUserBody, User, UserInfo } from "@core";
|
||||
import { Services } from "../express/server";
|
||||
import { CreateUserBody, User, UserInfo } from '@core';
|
||||
import { Services } from '../express/server';
|
||||
|
||||
export function Create(services: Services): (tracker: string, user: CreateUserBody) => Promise<UserInfo> {
|
||||
export function Create(
|
||||
services: Services,
|
||||
): (tracker: string, user: CreateUserBody) => Promise<UserInfo> {
|
||||
const { db } = services;
|
||||
const coll = db.collection("users");
|
||||
const coll = db.collection('users');
|
||||
|
||||
return async (tracker, user) => {
|
||||
await coll.insertOne(user);
|
||||
return {
|
||||
name: "test"
|
||||
}
|
||||
}
|
||||
}
|
||||
name: 'test',
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
import { CreateUserBody, UserInfo } from "@core";
|
||||
import { Services } from "../framework/express/server";
|
||||
import * as mongo from "../framework/mongo/user";
|
||||
import { CreateUserBody, UserInfo } from '@core';
|
||||
import { Services } from '../framework/express/server';
|
||||
import * as mongo from '../framework/mongo/user';
|
||||
|
||||
export function Create(services: Services): (tracker: string, user: CreateUserBody) => Promise<UserInfo> {
|
||||
export function Create(
|
||||
services: Services,
|
||||
): (tracker: string, user: CreateUserBody) => Promise<UserInfo> {
|
||||
const createUser = mongo.Create(services);
|
||||
|
||||
return async (tracker, user) => {
|
||||
return createUser(tracker, user);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -7,24 +7,15 @@
|
||||
"outDir": "dist",
|
||||
"sourceMap": false,
|
||||
"paths": {
|
||||
"@core": [
|
||||
"../core/src"
|
||||
]
|
||||
"@core": ["../core/src"]
|
||||
}
|
||||
},
|
||||
"lib": [
|
||||
"es2015"
|
||||
],
|
||||
"include": [
|
||||
"src/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules/*",
|
||||
"dist/*"
|
||||
],
|
||||
"lib": ["es2015"],
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules/*", "dist/*"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../core"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user