Skip to content

Commit 420c336

Browse files
committed
- package update
- refactoring server tests - logs location change - adding nodemon.json
1 parent b9e108a commit 420c336

File tree

8 files changed

+39
-42
lines changed

8 files changed

+39
-42
lines changed

.env

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ MONGODB_URI=mongodb://hackp0int:[email protected]:19675/profiles
22
SECRET_TOKEN=YOUR_AUTH0_SECRET
33
PORT=8089
44
ENV=development
5+
SERVER_LOGS_FOLDER = ./server/logs

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# dependencies
99
/node_modules
10-
/logs
10+
/server/logs
1111
# IDEs and editors
1212
/.idea
1313
.project
@@ -43,4 +43,3 @@ Thumbs.db
4343

4444
# git
4545
package-lock.json
46-
nodemon.json

nodemon.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"watch": [
3+
"server/**/*.ts"
4+
],
5+
"ignore": [
6+
"server/**/*.spec.ts"
7+
],
8+
"ext": "ts js json"
9+
}

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@
3333
"cookie-parser": "latest",
3434
"core-js": "^2.5.3",
3535
"cors": "^2.8.4",
36-
"dotenv": "^5.0.0",
36+
"dotenv": "^5.0.1",
3737
"errorhandler": "latest",
38-
"inversify": "^4.10.0",
38+
"inversify": "^4.11.1",
3939
"method-override": "^2.3.10",
4040
"mocha": "^5.0.1",
4141
"mocha-typescript": "^1.1.12",
4242
"morgan": "^1.9.0",
4343
"path": "^0.12.7",
4444
"reflect-metadata": "^0.1.12",
4545
"rxjs": "^5.5.6",
46-
"typeorm": "^0.1.12",
46+
"typeorm": "^0.1.13",
4747
"winston": "^2.4.0",
4848
"zone.js": "^0.8.20"
4949
},
@@ -68,7 +68,7 @@
6868
"codelyzer": "~4.1.0",
6969
"concurrently": "^3.5.1",
7070
"cookie-parser": "latest",
71-
"jasmine-core": "~2.99.1",
71+
"jasmine-core": "~3.0.0",
7272
"jasmine-spec-reporter": "~4.2.1",
7373
"karma": "~2.0.0",
7474
"karma-chrome-launcher": "~2.2.0",

server/infrastructure/api-server.ts

+1-18
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,7 @@ export class ApiServer extends Server {
5353

5454
// handle CORS
5555
this.app.use(cors());
56-
// this.app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
57-
//
58-
// // Website you wish to allow to connect
59-
// res.setHeader('Access-Control-Allow-Origin', '*');
60-
//
61-
// // Request methods you wish to allow
62-
// res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
63-
//
64-
// // Request headers you wish to allow
65-
// res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
66-
//
67-
// // Set to true if you need the website to include cookies in the requests sent
68-
// // to the API (e.g. in case you use sessions)
69-
// res.setHeader('Access-Control-Allow-Credentials', 'true');
70-
//
71-
// // Pass to next layer of middleware
72-
// next(err);
73-
// });
56+
7457
// error handling
7558
this.app.use(errorHandler());
7659
}

server/infrastructure/utils/logger.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { Logger, LoggerInstance, LoggerOptions, transports } from 'winston';
22
import * as fs from 'fs';
33
import * as dotenv from 'dotenv';
44

5-
const logsDir = 'logs';
65
const env = dotenv.config({path: '.env'});
6+
const logsDir = process.env.SERVER_LOGS_FOLDER;
77

88
console.log(env);
9-
if (!fs.existsSync(`./${logsDir}`)) {
10-
fs.mkdirSync(`./${logsDir}`);
9+
if (!fs.existsSync(`${logsDir}`)) {
10+
fs.mkdirSync(`${logsDir}`);
1111
}
1212

1313
export const logger: LoggerInstance = new Logger(<LoggerOptions> {
@@ -24,7 +24,7 @@ export const logger: LoggerInstance = new Logger(<LoggerOptions> {
2424
}),
2525
new transports.File({
2626
level: 'info',
27-
filename: `./${logsDir}/all-logs.log`,
27+
filename: `${logsDir}/all-logs.log`,
2828
handleExceptions: true,
2929
json: true,
3030
maxsize: 5242880,

server/tests/abstract/base.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { ApiServer } from '../../infrastructure/api-server';
2+
import * as chai from 'chai';
3+
import { Server } from '../../infrastructure/server';
4+
5+
export abstract class BaseTest {
6+
protected apiServer: Server = ApiServer.bootstrap();
7+
8+
public static before() {
9+
chai.use(require('chai-http'));
10+
const expect = chai.expect;
11+
const should = chai.should();
12+
}
13+
14+
public static after() {
15+
console.log('Shutting down the server!');
16+
}
17+
}

server/tests/index-route.spec.ts

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
import { suite, test } from 'mocha-typescript';
22
import * as chai from 'chai';
3-
import { Server } from '../infrastructure/server';
4-
import { ApiServer } from '../infrastructure/api-server';
3+
import { BaseTest } from './abstract/base';
54

6-
@suite class UserApiTest {
7-
private apiServer: Server = ApiServer.bootstrap();
8-
9-
public static before() {
10-
chai.use(require('chai-http'));
11-
const expect = chai.expect;
12-
const should = chai.should();
13-
}
14-
public static after() {
15-
console.log('Shutting down the server!');
16-
}
5+
@suite class UserApiTest extends BaseTest {
176

187
@test('should receive user token v1')
198
public shouldGetTheToken() {
209
chai.request(this.apiServer.app)
2110
.get('/api/v1/ping')
2211
.end((err, res) => {
23-
console.log('run test');
2412
res.should.have.status(200);
2513
res.body.should.have.property('token', 1);
2614
});

0 commit comments

Comments
 (0)