initial commit v1
This commit is contained in:
3
server/.gitignore
vendored
Normal file
3
server/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
admin/
|
||||
client/
|
||||
build/
|
||||
28
server/package.json
Normal file
28
server/package.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "catherine-league-server",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "src/index.ts",
|
||||
"scripts": {
|
||||
"start": "ts-node-dev --respawn --transpileOnly ./src/index.ts",
|
||||
"build": "tsc --resolveJsonModule",
|
||||
"test": "ts-node-dev src/test.ts",
|
||||
"lint": "tslint -c tslint.json -p tsconfig.json"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"mysql": "^2.18.1",
|
||||
"ts-node-dev": "^1.0.0-pre.44",
|
||||
"uuid": "^7.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.6",
|
||||
"@types/mysql": "^2.1.4",
|
||||
"typescript": "^3.8.3",
|
||||
"tslint": "^5.18.0",
|
||||
"tslint-config-airbnb": "^5.11.1"
|
||||
}
|
||||
}
|
||||
139
server/src/index.ts
Normal file
139
server/src/index.ts
Normal file
@@ -0,0 +1,139 @@
|
||||
import express from 'express';
|
||||
import http from 'http';
|
||||
import cors from 'cors';
|
||||
import mysql from 'mysql';
|
||||
import { v1 } from 'uuid';
|
||||
|
||||
const port: number = 443;
|
||||
const app: express.Express = express();
|
||||
const httpServer: http.Server = http.createServer(app);
|
||||
const tournaments: Record<string, number> = {};
|
||||
const players: Record<string, number> = {};
|
||||
const connection = mysql.createPool({
|
||||
connectionLimit: 10,
|
||||
host: 'test-db.csmrqtei38qi.ap-northeast-1.rds.amazonaws.com',
|
||||
user: 'admin',
|
||||
password: '12341234',
|
||||
database: 'catherine_league'
|
||||
});
|
||||
connection.query(
|
||||
`SELECT id, tournament_key
|
||||
FROM tournaments`,
|
||||
(error: mysql.MysqlError | null, results: any) => {
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
if (results.length > 0) {
|
||||
results.forEach((result: any) => {
|
||||
tournaments[result.tournament_key] = result.id;
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
connection.query(
|
||||
`SELECT id, player_key FROM players;`,
|
||||
(error: mysql.MysqlError | null, results: any) => {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
return;
|
||||
}
|
||||
if (results.length > 0) {
|
||||
results.forEach((result: any) => {
|
||||
players[result.player_key] = result.id;
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
app.use(cors());
|
||||
app.options('*', cors());
|
||||
}
|
||||
|
||||
app.get('/api/players/:key', (req: any, res: any) => {
|
||||
if (req.params && req.params.key && tournaments[req.params.key]) {
|
||||
const sqlToPrepare = `SELECT p.id, p.player_key, p.player_name,p.description,p.image,c.name_id, c.name, c.name_jp
|
||||
FROM players p
|
||||
JOIN player_to_tournament ptt
|
||||
on p.id = ptt.player_id
|
||||
JOIN characters c
|
||||
on c.id = p.character_id
|
||||
where ptt.tournament_id = ?`;
|
||||
const sql = mysql.format(sqlToPrepare, [tournaments[req.params.key]]);
|
||||
connection.query(sql,
|
||||
(error: mysql.MysqlError | null, results: any) => {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
// players not found
|
||||
} else {
|
||||
res.send(results);
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
// send error
|
||||
}
|
||||
});
|
||||
app.get('/api/players', (req: any, res: any) => {
|
||||
connection.query(
|
||||
`SELECT p.id, p.player_key, p.player_name,p.description,p.image,c.name_id, c.name, c.name_jp
|
||||
FROM players p
|
||||
JOIN characters c
|
||||
on c.id = p.character_id`,
|
||||
(error: mysql.MysqlError | null, results: any) => {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
// players not found
|
||||
} else {
|
||||
res.send(results);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
app.get('/api/guide', (req: any, res: any) => {
|
||||
connection.query(
|
||||
`SELECT *
|
||||
FROM guide`,
|
||||
(error: mysql.MysqlError | null, results: any) => {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
res.send([]);
|
||||
} else {
|
||||
res.send(results);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
app.get('/api/archive', (req: any, res: any) => {
|
||||
connection.query(
|
||||
`SELECT *
|
||||
FROM archive`,
|
||||
(error: mysql.MysqlError | null, results: any) => {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
res.send([]);
|
||||
} else {
|
||||
res.send(results);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
app.get('/api/contact', (req: any, res: any) => {
|
||||
connection.query(
|
||||
`SELECT *
|
||||
FROM contact`,
|
||||
(error: mysql.MysqlError | null, results: any) => {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
res.send([]);
|
||||
} else {
|
||||
res.send(results);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
app.use(express.static('client'));
|
||||
|
||||
httpServer.listen(port, () => {
|
||||
console.log(`listening to port ${port}`);
|
||||
});
|
||||
0
server/src/models/index.ts
Normal file
0
server/src/models/index.ts
Normal file
0
server/src/test.ts
Normal file
0
server/src/test.ts
Normal file
24
server/tsconfig.json
Normal file
24
server/tsconfig.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": "1.5.1",
|
||||
"compilerOptions": {
|
||||
"target": "es2019",
|
||||
"module": "commonjs",
|
||||
"allowJs": true,
|
||||
"declaration": false,
|
||||
"declarationMap": false,
|
||||
"outDir": "build",
|
||||
"noImplicitAny": false,
|
||||
"removeComments": true,
|
||||
"noLib": false,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"alwaysStrict": true,
|
||||
"esModuleInterop": true,
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
]
|
||||
}
|
||||
37
server/tslint.json
Normal file
37
server/tslint.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"defaultSeverity": "error",
|
||||
"extends": [
|
||||
"tslint:recommended",
|
||||
"tslint-config-airbnb"
|
||||
],
|
||||
"jsRules": {},
|
||||
"rules": {
|
||||
"curly": [true, "ignore-same-line"],
|
||||
"typedef": [
|
||||
true,
|
||||
"call-signature",
|
||||
"arrow-call-signature",
|
||||
"parameter",
|
||||
"arrow-parameter",
|
||||
"member-variable-declaration",
|
||||
"property-declaration"
|
||||
],
|
||||
"no-any": false,
|
||||
"quotemark": [true, "single"],
|
||||
"trailing-comma": false,
|
||||
"max-line-length": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": false,
|
||||
"no-console": false,
|
||||
"align": false,
|
||||
"no-default-export": true
|
||||
},
|
||||
"rulesDirectory": [],
|
||||
"linterOptions": {
|
||||
"exclude": [
|
||||
"src/lib/**/*",
|
||||
"**/*.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user