use koa-sslify

This commit is contained in:
2019-12-22 20:53:38 +03:00
parent 7a68132346
commit 1aa1768c93
4 changed files with 29 additions and 1 deletions

14
package-lock.json generated
View File

@@ -264,6 +264,15 @@
"@types/koa": "*"
}
},
"@types/koa-sslify": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/@types/koa-sslify/-/koa-sslify-4.0.1.tgz",
"integrity": "sha512-RS0RIQuHp4G7ZR2kMHDw3Lnr0yRB4em50TwFm/tOSCPFaDwyKeU26F6tEULOrkS+J7zYZSB3h2pDTPaNhTEK0w==",
"dev": true,
"requires": {
"@types/koa": "*"
}
},
"@types/koa-static": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/@types/koa-static/-/koa-static-4.0.1.tgz",
@@ -2713,6 +2722,11 @@
"resolve-path": "^1.4.0"
}
},
"koa-sslify": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/koa-sslify/-/koa-sslify-4.0.3.tgz",
"integrity": "sha512-5RwsRc+Zkawoq9ev5pNAPP8r+wj4Eqo3b7IfSXrpYISBDNo0fwrMcYMioR+B00piV9NpXqPZA4gh36SpIeZSvw=="
},
"koa-static": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/koa-static/-/koa-static-5.0.0.tgz",

View File

@@ -12,6 +12,7 @@
"@types/koa-logger": "^3.1.1",
"@types/koa-router": "^7.0.42",
"@types/koa-send": "^4.1.2",
"@types/koa-sslify": "^4.0.1",
"@types/koa-static": "^4.0.1",
"@types/koa__cors": "^2.2.3",
"@types/lodash": "^4.14.149",
@@ -50,6 +51,7 @@
"koa-logger": "^3.2.1",
"koa-router": "^7.4.0",
"koa-send": "^5.0.0",
"koa-sslify": "^4.0.3",
"koa-static": "^5.0.0",
"lodash": "^4.17.15",
"mysql": "^2.17.1",

View File

@@ -6,9 +6,10 @@ import * as bodyParser from "koa-body";
import * as jwt from "koa-jwt";
import * as logger from "koa-logger";
import * as send from "koa-send";
import sslify from "koa-sslify";
import * as serve from "koa-static";
import { config } from "~config";
import { config, EnvType } from "~config";
import { docsRouter } from "~routes/docs";
import { userRouter } from "~routes/users";
@@ -17,6 +18,9 @@ export const app = new Koa();
app.use(cors());
app.use(logger());
app.use(bodyParser());
if (config.env === EnvType.production) {
app.use(sslify());
}
app.use(
jwt({
secret: config.jwtSecret,

View File

@@ -1,13 +1,19 @@
import * as fs from "fs";
import { ConnectionOptions } from "typeorm";
export enum EnvType {
production, development, test
}
export interface IConfig {
env: EnvType;
port: number;
jwtSecret: string;
dbConnectionOptions: ConnectionOptions | null;
}
const production: IConfig = {
env: EnvType.production,
port: parseInt(process.env.PORT, 10) || 3000,
jwtSecret: process.env.JWT_SECRET,
dbConnectionOptions: null,
@@ -15,11 +21,13 @@ const production: IConfig = {
const development: IConfig = {
...production,
env: EnvType.development,
jwtSecret: "DEVSECRET",
};
const test: IConfig = {
...production,
env: EnvType.test,
jwtSecret: "TESTSECRET",
dbConnectionOptions:
process.env.NODE_ENV === "test"