Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wip] trying to fix bugs in read request body
- Loading branch information
Showing
11 changed files
with
379 additions
and
46 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as dotenv from 'dotenv'; | ||
|
||
dotenv.config({ path: '.env' }); | ||
|
||
export interface IConfig { | ||
port: number; | ||
debugLogging: boolean; | ||
dbsslconn: boolean; | ||
jwtSecret: string; | ||
} | ||
|
||
const config: IConfig = { | ||
port: +process.env.PORT || 3000, | ||
debugLogging: process.env.NODE_ENV == 'development', | ||
dbsslconn: process.env.NODE_ENV != 'development', | ||
jwtSecret: process.env.JWT_SECRET || 'your-secret-whatever', | ||
}; | ||
|
||
export { config }; |
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,6 @@ | ||
interface importPackageRequest { | ||
linkedTo: string | ||
} | ||
export { | ||
importPackageRequest | ||
} |
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,12 +1,15 @@ | ||
import { BaseContext } from 'koa'; | ||
import { Package } from '../dynamo/model' | ||
|
||
import { Context } from 'koa'; | ||
import { Package } from '../dynamo/entity'; | ||
import { importPackageRequest } from './entity' | ||
export default class PackageController { | ||
public static async importPackage (ctx: BaseContext) { | ||
public static async importPackage (ctx: Context) { | ||
const toImportPackage : Package = new Package(); | ||
console.log(ctx.body) | ||
console.log(typeof(ctx.request.body)); | ||
|
||
let ipr:importPackageRequest; | ||
Object.assign(ipr, ctx.request.body); | ||
toImportPackage.isSymbol = true; | ||
toImportPackage.linkedTo = ctx.body.linkedTo; | ||
toImportPackage.linkedTo = ipr.linkedTo; | ||
console.log(toImportPackage) | ||
} | ||
} |
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
File renamed without changes.
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,44 @@ | ||
import * as Koa from 'koa'; | ||
import { config } from './config'; | ||
import * as winston from 'winston'; | ||
|
||
export function logger(winstonInstance: any) { | ||
return async(ctx: Koa.Context, next: () => Promise<any>) => { | ||
|
||
const start = new Date().getMilliseconds(); | ||
|
||
await next(); | ||
|
||
const ms = new Date().getMilliseconds() - start; | ||
|
||
let logLevel: string; | ||
if (ctx.status >= 500) { | ||
logLevel = 'error'; | ||
} | ||
if (ctx.status >= 400) { | ||
logLevel = 'warn'; | ||
} | ||
if (ctx.status >= 100) { | ||
logLevel = 'info'; | ||
} | ||
|
||
const msg: string = `${ctx.method} ${ctx.originalUrl} ${ctx.status} ${ms}ms`; | ||
|
||
winstonInstance.configure({ | ||
level: config.debugLogging ? 'debug' : 'info', | ||
transports: [ | ||
// | ||
// - Write all logs error (and below) to `error.log`. | ||
new winston.transports.File({ filename: 'error.log', level: 'error' }), | ||
// | ||
// - Write to all logs with specified level to console. | ||
new winston.transports.Console({ format: winston.format.combine( | ||
winston.format.colorize(), | ||
winston.format.simple() | ||
) }) | ||
] | ||
}); | ||
|
||
winstonInstance.log(logLevel, msg); | ||
}; | ||
} |
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
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,29 +1,60 @@ | ||
{ | ||
"defaultSeverity": "error", | ||
"extends": [ | ||
"tslint:recommended" | ||
], | ||
"jsRules": {}, | ||
"rules": { | ||
"quotemark": [ | ||
"class-name": true, | ||
"comment-format": [ | ||
true, | ||
"single" | ||
"check-space" | ||
], | ||
"no-console": [ | ||
false | ||
"indent": [ | ||
true, | ||
"spaces" | ||
], | ||
"one-line": [ | ||
true, | ||
"check-open-brace", | ||
"check-whitespace" | ||
], | ||
"object-literal-sort-keys": [ | ||
false | ||
"no-var-keyword": true, | ||
"quotemark": [ | ||
true, | ||
"single", | ||
"avoid-escape" | ||
], | ||
"semicolon": [ | ||
true, | ||
"always", | ||
"ignore-bound-class-methods" | ||
], | ||
"whitespace": [ | ||
true, | ||
"check-branch", | ||
"check-decl", | ||
"check-operator", | ||
"check-module", | ||
"check-separator", | ||
"check-type" | ||
], | ||
"typedef-whitespace": [ | ||
true, | ||
{ | ||
"call-signature": "nospace", | ||
"index-signature": "nospace", | ||
"parameter": "nospace", | ||
"property-declaration": "nospace", | ||
"variable-declaration": "nospace" | ||
}, | ||
{ | ||
"call-signature": "onespace", | ||
"index-signature": "onespace", | ||
"parameter": "onespace", | ||
"property-declaration": "onespace", | ||
"variable-declaration": "onespace" | ||
} | ||
], | ||
"no-string-literal": false, | ||
"triple-equals": [ | ||
false | ||
] | ||
}, | ||
"rulesDirectory": [] | ||
"no-internal-module": true, | ||
"no-trailing-whitespace": true, | ||
"no-null-keyword": true, | ||
"prefer-const": true, | ||
"jsdoc-format": true | ||
} | ||
} |