UNPKG

ts-site-starter

Version:

![npm](https://img.shields.io/npm/v/ts-site-starter.svg) ![license](https://img.shields.io/npm/l/ts-site-starter.svg) ![github-issues](https://img.shields.io/github/issues/wspecs/ts-site-starter.svg)

116 lines (82 loc) 2.2 kB
# ${pkg.name} ${badge('npm')} ${badge('npm-license')} ${badge('github-issues')} ${pkg.description} ${badge('nodei')} ${badge('travis-status')} ${badge('github-stars')} ${badge('github-forks')} ${badge('github-forks')} ${badge('dependencies')} ${badge('devDependencies')} ## Features - Configure express application. - Written in TS ## Usage ### lib/app-routes.ts ```js const siteStarter = require('tsm.name'); import {AppResponse, BasicRoutes} from 'ts-site-starter'; import {Request} from 'express'; export class AppRoutes extends BasicRoutes { constructor(basePath: string) { super(basePath); this.addRoutes(); } homePage(req: Request, res: AppResponse) { res.serve('home', {}); } addRoutes() { this.router.get('/', this.homePage.bind(this)); } } ``` ### index.ts ```js import * as express from "express"; import * as log from 'great-logs'; import { configureRest, serverConfig } from 'ts-site-starter'; import { AppRoutes } from './lib/app-routes'; /** * The server. * @class Server */ export class Server { public app: express.Application; /** * Constructor. * @class Server * @constructor */ constructor() { //create expressjs application this.app = express(); configureRest(this.app, express); } routeApp() { const routes = (new AppRoutes('')).getRoutes(); this.app.use(routes); } start() { this.routeApp(); const port = serverConfig.getPort(); this.app.listen(port, function () { log.info('port: %s', port); log.info('url: %s', serverConfig.base); }); } } // Start the application new Server().start(); ``` ## Install `npm install --save ${pkg.name}` ## Scripts ${scripts()} ## Dependencies ${dependencies()} ## Contributing Contributions welcome; Please submit all pull requests against the master branch. If your pull request contains TypeScript patches or features, you should include relevant unit tests. Please check the [Contributing Guidelines](contributng.md) for more details. Thanks! ## Author ${author()} ## License ${license()}