-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
693 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"printWidth": 120, | ||
"semi": false, | ||
"semi": true, | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
database: | ||
name: tinylog | ||
host: 127.0.0.1 | ||
port: 3306 | ||
username: root | ||
password: | ||
logging: true | ||
|
||
env: development | ||
port: 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"type": "mysql", | ||
"host": "127.0.0.1", | ||
"port": 3306, | ||
"username": "root", | ||
"database": "tinylog", | ||
"entities": ["src/entities/**/*.ts"], | ||
"migrations": ["src/migrations/**/*.ts"], | ||
"cli": { | ||
"entitiesDir": "./src/entities", | ||
"migrationsDir": "./src/migrations" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,33 @@ | ||
/** | ||
* .,:,,, .::,,,::. | ||
* .::::,,;;, .,;;:,,....:i: | ||
* :i,.::::,;i:. ....,,:::::::::,.... .;i:,. ......;i. | ||
* :;..:::;::::i;,,:::;:,,,,,,,,,,..,.,,:::iri:. .,:irsr:,.;i. | ||
* ;;..,::::;;;;ri,,,. ..,,:;s1s1ssrr;,.;r, | ||
* :;. ,::;ii;:, . ................... .;iirri;;;,,;i, | ||
* ,i. .;ri:. ... ............................ .,,:;:,,,;i: | ||
* :s,.;r:... ....................................... .::;::s; | ||
* ,1r::. .............,,,.,,:,,........................,;iir; | ||
* ,s;........... ..::.,;:,,. ...............,;1s | ||
* :i,..,. .,:,,::,. .......... .......;1, | ||
* ir,....:rrssr;:, ,,.,::. .r5S9989398G95hr;. ....,.:s, | ||
* ;r,..,s9855513XHAG3i .,,,,,,,. ,S931,.,,.;s;s&BHHA8s.,..,..:r: | ||
* :r;..rGGh, :SAG;;G@BS:.,,,,,,,,,.r83: hHH1sXMBHHHM3..,,,,.ir. | ||
* ,si,.1GS, sBMAAX&MBMB5,,,,,,:,,.:&8 3@HXHBMBHBBH#X,.,,,,,,rr | ||
* ;1:,,SH: .A@&&B#&8H#BS,,,,,,,,,.,5XS, 3@MHABM&59M#As..,,,,:,is, | ||
* .rr,,,;9&1 hBHHBB&8AMGr,,,,,,,,,,,:h&&9s; r9&BMHBHMB9: . .,,,,;ri. | ||
* :1:....:5&XSi;r8BMBHHA9r:,......,,,,:ii19GG88899XHHH&GSr. ...,:rs. | ||
* ;s. .:sS8G8GG889hi. ....,,:;:,.:irssrriii:,. ...,,i1, | ||
* ;1, ..,....,,isssi;, .,,. ....,.i1, | ||
* ;h: i9HHBMBBHAX9: . ...,,,rs, | ||
* ,1i.. :A#MBBBBMHB##s ....,,,;si. | ||
* .r1,.. ,..;3BMBBBHBB#Bh. .. ....,,,,,i1; | ||
* :h;.. .,..;,1XBMMMMBXs,.,, .. :: ,. ....,,,,,,ss. | ||
* ih: .. .;;;, ;;:s58A3i,.. ,. ,.:,,. ...,,,,,:,s1, | ||
* .s1,.... .,;sh, ,iSAXs;. ,. ,,.i85 ...,,,,,,:i1; | ||
* .rh: ... rXG9XBBM#M#MHAX3hss13&&HHXr .....,,,,,,,ih; | ||
* .s5: ..... i598X&&A&AAAAAA&XG851r: ........,,,,:,,sh; | ||
* . ihr, ... . .. ........,,,,,;11:. | ||
* ,s1i. ... ..,,,..,,,.,,.,,.,.. ........,,.,,.;s5i. | ||
* .:s1r,...................... ..............;shs, | ||
* . .:shr:. .... ..............,ishs. | ||
* .,issr;,... ...........................,is1s;. | ||
* .,is1si;:,....................,:;ir1sr;, | ||
* ..:isssssrrii;::::::;;iirsssssr;:.. | ||
* .,::iiirsssssssssrri;;:. | ||
* | ||
* For the brave souls who get this far: You are the chosen ones, | ||
* the valiant knights of programming who toil away, without rest, | ||
* fixing our most awful code. To you, true saviors, kings of men, | ||
* I say this: never gonna give you up, never gonna let you down, | ||
* never gonna run around and desert you. Never gonna make you cry, | ||
* never gonna say goodbye. Never gonna tell a lie and hurt you. | ||
* | ||
* 致终于来到这里的勇敢的人: | ||
* 你是被上帝选中的人,是英勇的、不敌辛苦的、不眠不休的来修改我们这最棘手的代码的编程骑士。 | ||
* 你,我们的救世主,人中之龙,我要对你说:永远不要放弃,永远不要对自己失望,永远不要逃走,辜负了自己, | ||
* 永远不要哭啼,永远不要说再见,永远不要说谎来伤害自己。 | ||
*/ | ||
console.log('Hello World!') | ||
import 'reflect-metadata'; | ||
import * as Koa from 'koa'; | ||
import * as logger from 'koa-logger'; | ||
import * as config from 'config'; | ||
import { useContainer as useContainerForRoute, useKoaServer } from 'routing-controllers'; | ||
import { Container } from 'typedi'; | ||
import { useContainer as useContainerForOrm } from 'typeorm'; | ||
import { database } from './libraries/database'; | ||
|
||
const { port } = config; | ||
|
||
useContainerForRoute(Container); | ||
useContainerForOrm(Container); | ||
|
||
const app = new Koa(); | ||
|
||
app.use(logger()); | ||
|
||
useKoaServer(app, { | ||
cors: true, | ||
routePrefix: '/v1', | ||
controllers: [`${__dirname}/controllers/*.{js,ts}`], | ||
defaultErrorHandler: true | ||
}); | ||
|
||
export const connection = database().then(async c => { | ||
return new Promise(resolve => { | ||
app.listen(port, () => { | ||
console.log(`[APP] Listen on ${port} in ${config.env} enviroment`); | ||
resolve(app.callback()); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'reflect-metadata'; | ||
import * as config from 'config'; | ||
import * as path from 'path'; | ||
import { Connection, createConnection } from 'typeorm'; | ||
|
||
const dbConfig = config.database; | ||
|
||
const root = path.resolve(__dirname, '..'); | ||
const entityPath = `${root}/entities/*.{js,ts}`; | ||
const migrationPath = `${root}/migrations/*.{js,ts}`; | ||
|
||
export const database: () => Promise<Connection> = async () => | ||
createConnection({ | ||
type: 'mysql', | ||
host: dbConfig.host, | ||
port: dbConfig.port, | ||
username: dbConfig.username, | ||
password: dbConfig.password, | ||
database: dbConfig.name, | ||
entities: [entityPath], | ||
migrations: [migrationPath], | ||
migrationsRun: true, | ||
cli: { | ||
migrationsDir: path.resolve(__dirname, '..', 'migrations') | ||
}, | ||
charset: 'utf8mb4_general_ci', | ||
logging: dbConfig.logging | ||
}).then(c => { | ||
console.log('[DB] Database Connected'); | ||
return c; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
declare module 'config' { | ||
export const database: { | ||
name: string; | ||
host: string; | ||
port: number; | ||
username: string; | ||
password: string; | ||
sync: boolean; | ||
logging: boolean; | ||
}; | ||
|
||
export const env: string; | ||
export const port: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.