Skip to content

Commit

Permalink
updated packages
Browse files Browse the repository at this point in the history
now using npm for typings
added integration test
updated project structure by adding services and config folders
removed gulp
  • Loading branch information
Sul committed Oct 15, 2016
1 parent 50c26ae commit 2007623
Show file tree
Hide file tree
Showing 26 changed files with 278 additions and 3,683 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ node_modules
coverage
checkstyle-result.xml

# generated js scripts from type-script
dist
app/**/*.js
app/**/*.map
test/**/*.js
test/**/*.map
46 changes: 46 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/app/app.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"console": "internalConsole",
"sourceMaps": true,
"outFiles": []
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5858,
"address": "localhost",
"restart": false,
"sourceMaps": true,
"outFiles": [],
"localRoot": "${workspaceRoot}",
"remoteRoot": null
},
{
"name": "Attach to Process",
"type": "node",
"request": "attach",
"processId": "${command.PickProcess}",
"port": 5858,
"sourceMaps": false,
"outFiles": []
}
]
}
15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Place your settings in this file to overwrite default and user settings.
{
"explorer.openEditors.visible": 0,
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/.DS_Store": true,
"app/**/*.js": true,
"app/**/*.map": true,
"test/**/*.js": true,
"test/**/*.map": true
},
"typescript.tsdk": "node_modules/typescript/lib"
}
20 changes: 10 additions & 10 deletions app/app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var fs = require('fs');
import restify = require('restify');
import {settings} from './config';
import {logger} from './logger';
import * as fs from 'fs';
import * as restify from 'restify';
import { settings } from './config/config';
import { logger } from './services/logger';

var api = restify.createServer({
export let api = restify.createServer({
name: settings.name
});

Expand All @@ -17,13 +17,13 @@ api.use(restify.authorizationParser());
api.use(restify.fullResponse());


fs.readdirSync(__dirname + '/routes').forEach(function(routeConfig:string) {
fs.readdirSync(__dirname + '/routes').forEach(function (routeConfig: string) {
if (routeConfig.substr(-3) === '.js') {
var route = require(__dirname + '/routes/' + routeConfig);
let route = require(__dirname + '/routes/' + routeConfig);
route.routes(api);
}
});

api.listen(settings.port, function() {
console.log(`INFO: ${settings.name} is running at ${api.url}`);
});
api.listen(settings.port, function () {
logger.info(`INFO: ${settings.name} is running at ${api.url}`);
});
21 changes: 0 additions & 21 deletions app/config.ts

This file was deleted.

15 changes: 15 additions & 0 deletions app/config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {Config} from '../types';

let env = process.env.NODE_ENV || 'development';

export let settings: Config = {
name: 'restify-typescript-seed',
version: '2.0.0',
port: 3000,
env: 'dev'
};

if (env === 'production') {
settings.env = 'prod';
// other production settings
}
7 changes: 4 additions & 3 deletions app/controllers/SampleRouteController.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import restify = require('restify');
import * as restify from 'restify';
import { logger } from '../services/logger';

export default class SampleRouteController {

get(req: restify.Request, res: restify.Response, next: restify.Next) {
public get(req: restify.Request, res: restify.Response, next: restify.Next) {
logger.info('accessing ping route');
res.json(200, 'pong');
return next();
}
Expand Down
16 changes: 0 additions & 16 deletions app/logger.ts

This file was deleted.

2 changes: 1 addition & 1 deletion app/routes/sampleRoute.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import restify = require('restify');
import * as restify from 'restify';
import sampleRouteController from '../controllers/SampleRouteController'

function sampleRoute(api:restify.Server) {
Expand Down
25 changes: 25 additions & 0 deletions app/services/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as bunyan from 'bunyan';
import * as stream from 'stream';

let infoStream = new stream.Writable();
infoStream.writable = true;

infoStream.write = (info: any): boolean => {

console.log(JSON.parse(info).msg);
return true;
};

export let logger = bunyan.createLogger({
name: 'myapp',
streams: [
{
level: 'info',
stream: infoStream
},
{
level: 'error',
path: `error.log`
}
]
});
30 changes: 0 additions & 30 deletions app/test/controllers/SampleRouteController.spec.ts

This file was deleted.

6 changes: 6 additions & 0 deletions app/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface Config {
name: string;
port: number;
env: string;
version: string;
}
10 changes: 0 additions & 10 deletions gulpConfig.js

This file was deleted.

32 changes: 0 additions & 32 deletions gulpfile.js

This file was deleted.

28 changes: 17 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,31 @@
"description": "a seed project for creating http service using restify written in typescript",
"main": "app.js",
"scripts": {
"test": "mocha dist/test/controllers/",
"compile": "tsc"
"test": "node_modules/.bin/_mocha test/unit/**/*.spec.js",
"compile": "node_modules/.bin/tsc",
"start": "node app/app.js"
},
"keywords": [
"typescript",
"restify"
],
"author": "Sul.Aga",
"license": "MIT",
"dependencies": {
"restify": "^4.0.3"
"dependencies": {
"@types/chai": "^3.4.34",
"@types/mocha": "^2.2.32",
"@types/node": "^6.0.45",
"@types/restify": "^2.0.33",
"@types/sinon": "^1.16.31",
"@types/supertest": "^1.1.31",
"restify": "^4.1.1"
},
"devDependencies": {
"chai": "^3.4.1",
"gulp": "^3.9.0",
"gulp-sourcemaps": "^1.6.0",
"gulp-typescript": "^2.9.2",
"mocha": "^2.3.4",
"sinon": "^1.17.2",
"typescript": "^1.6.2"
"chai": "^3.5.0",
"mocha": "^3.1.2",
"sinon": "^1.17.6",
"supertest": "^2.0.0",
"tslint": "^3.15.1",
"typescript": "^2.0.3"
}
}
23 changes: 23 additions & 0 deletions test/integration/controllers/SampleRouteController.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import chai = require('chai');
import { api as server } from '../../../app/app';
import * as supertest from 'supertest';

let expect = chai.expect;

describe('sample route controller', () => {

it('should return pong', (done) => {
supertest(server)
.get('/api/ping')
.end((err: any, response: supertest.Response) => {
if (err) {
done(err);
}
else {
expect(response.status).to.equal(200);
expect(response.body).to.equal('pong');
done();
}
});
});
});
Loading

0 comments on commit 2007623

Please sign in to comment.