当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript express类代码示例

本文整理汇总了TypeScript中express的典型用法代码示例。如果您正苦于以下问题:TypeScript express类的具体用法?TypeScript express怎么用?TypeScript express使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了express类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: startServer

import * as express from 'express';
import { Application } from 'express';
import { SeedWebServer } from '../seed/server';


export class ProjectWebServer extends SeedWebServer {
  // Override and modify the server code in this class.

  /**
   * This method is called once regardless of how the server is started, and this
   * is the starting point of the project's custom server code.
   */
  public startServer() {
    super.startServer();

    // Add project server startup code here.
  }
}

let app: Application = express();
let webServer = new ProjectWebServer(app);
export default webServer;
export function serveSPA() { webServer.serveSPA(); }
export function notifyLiveReload(e: any) { webServer.notifyLiveReload(e); }
export function serveDocs() { webServer.serveDocs(); }
export function serveCoverage() { webServer.serveCoverage(); }
export function serveProd() { webServer.serveProd(); }
开发者ID:hellofornow,项目名称:angular2-seed-advanced,代码行数:27,代码来源:server.ts

示例2: describe

describe("Check Pagination with custom keyword for limit and offset", function(){

  let app = express();
  ServiceLoader.loadService(app, new serviceCustomPagination());

  it("should return all the result", function(done){

    var data = DataHelper.getTestData();
    request(app)
    .get("/paginationCustom/666")
    .expect(function(res) {
      let expected = { _links:
        { self: {
          href:"/paginationCustom/666"}
        }, data: data}
        
      assert(res.body._links);
      assert.equal(res.body._links.self.href, expected._links.self.href);
      assert.equal(res.body.data.length, expected.data.length);

      DataHelper.testData(res.body.data, expected.data, 0, 13);

    }).end(done);
  });


  it("should return the four first result", function(done){

    request(app)
    .get("/paginationCustom/666?limite=4")
    .expect(function(res) {
      let expected = { _links:
        { self: {
          href:"/paginationCustom/666?limite=4"}
        }, data: [{firstName:"Peter", lastName:"Parker", secretIdentity: "Spiderman", offset:"0"},
        {firstName:"Bruce", lastName:"Wayne", secretIdentity: "Batman", offset:"1"},
        {firstName:"Clark", lastName:"Kent", secretIdentity: "Superman", offset:"2"},
        {firstName:"Tony", lastName:"Stark", secretIdentity: "Iron Man", offset:"3"}]}

      assert.equal(res.body._links.self.href, expected._links.self.href);
      assert.equal(res.body.data.length, expected.data.length);

      DataHelper.testData(res.body.data, expected.data, 0, 4);

    }).end(done);
  });

  it("should return all the result from offset 8", function(done){

    request(app)
    .get("/paginationCustom/666?offsetIndex=8")
    .expect(function(res) {
      let expected = { _links:
        { self: {
          href:"/paginationCustom/666?offsetIndex=8"}
        }, data: [{firstName:"Matt", lastName:"Murdock", secretIdentity: "Daredevil", offset:"8"},
        {firstName:"Wade", lastName:"Wilson", secretIdentity: "Deadpool", offset:"9"},
        {firstName:"Elektra", lastName:"Natchios", secretIdentity: "Elektra", offset:"10"},
        {firstName:"Dave", lastName:"Lizewski", secretIdentity: "Kick-Ass", offset:"11"},
        {firstName:"Franck", lastName:"Castle", secretIdentity: "Punisher", offset:"12"}]}

      assert.equal(res.body._links.self.href, expected._links.self.href);
      assert.equal(res.body.data.length, expected.data.length);

      DataHelper.testData(res.body.data, expected.data, 8, 5);

    }).end(done);
  });

  it("should return the first three result", function(done){

    request(app)
    .get("/paginationCustom/666?limite=3&index=0")
    .expect(function(res) {
      let expected = { _links:
        { self: {
          href:"/paginationCustom/666?limite=3&index=0"}
        }, data: [{firstName:"Peter", lastName:"Parker", secretIdentity: "Spiderman", offset:"0"},
        {firstName:"Bruce", lastName:"Wayne", secretIdentity: "Batman", offset:"1"},
        {firstName:"Clark", lastName:"Kent", secretIdentity: "Superman", offset:"2"}]}
      assert.equal(res.body._links.self.href, expected._links.self.href);
      assert.equal(res.body.data.length, expected.data.length);

      DataHelper.testData(res.body.data, expected.data, 0, 3);

    }).end(done);
  });

  it("should return the two result start with offset 5", function(done){

    request(app)
    .get("/paginationCustom/666?limite=2&index=5")
    .expect(function(res) {
      console.log(res.body);
      let expected = { _links:
        { self: {
          href:"/paginationCustom/666?limite=2&index=5"}
        }, data: [{firstName:"Bruce", lastName:"Banner", secretIdentity: "Hulk", offset:"5"},
                {firstName:"Natasha", lastName:"Romanoff", secretIdentity: "Black Widow", offset:"6"}]}

//.........这里部分代码省略.........
开发者ID:lynchmaniac,项目名称:threerest,代码行数:101,代码来源:test-custom-pagination.ts

示例3: Sequelize

import * as epilogue from 'epilogue';
import * as express from 'express';
import * as Sequelize from 'sequelize';

const database = new Sequelize({ });

epilogue.initialize({
    app: express(),
    sequelize: database
});

epilogue.initialize({
    app: express(),
    sequelize: database,
    base: ''
});

epilogue.initialize({
    app: express(),
    sequelize: database,
    base: '',
    updateMethod: ''
});

const User = database.define('User', {
    username: Sequelize.STRING,
    birthday: Sequelize.DATE
});

epilogue.resource({
    model: User,
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:31,代码来源:epilogue-tests.ts

示例4: express

import * as express from "express";
import * as sassMiddleware from "node-sass-middleware";
import * as path from "path";
var app = express();
app.use(sassMiddleware({
    /* Options */
    src: __dirname,
    dest: path.join(__dirname, 'public'),
    debug: true,
    outputStyle: 'compressed',
    prefix:  '/prefix'  // Where prefix is at <link rel="stylesheets" href="prefix/style.css"/>
}));
app.use(express.static(path.join(__dirname, 'public')));
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:13,代码来源:node-sass-middleware-tests.ts

示例5: enableProdMode

import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import { enableProdMode } from '@angular/core';
import { ngExpressEngine } from '@nguniversal/express-engine';
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';

import * as express from 'express';
import * as bodyParser from 'body-parser';
import * as cors from 'cors';
import * as compression from 'compression';

import { join } from 'path';

enableProdMode();

export const app = express();

app.use(compression());
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

// const DIST_FOLDER = join(process.cwd(), 'dist');

const {AppServerModuleNgFactory, LAZY_MODULE_MAP} = require('./dist/server/main');

app.engine('html', ngExpressEngine({
  bootstrap: AppServerModuleNgFactory,
  providers: [
    provideModuleMap(LAZY_MODULE_MAP)
  ]
开发者ID:nnoumegni,项目名称:jetcamer,代码行数:31,代码来源:server.ts

示例6: constructor

 constructor(private expressContactRouter: ExpressContactRouter) {
   // create expressjs application
   this.expressApplication = express();
 }
开发者ID:rajajhansi,项目名称:aspnetcore-aurelia-tutorial,代码行数:4,代码来源:express-application.ts

示例7: Express

/**
 * Created by chapeau on 7/25/16.
 */
///<reference path="../typings/index.d.ts"/>

import * as Express from 'express';
var app = Express();

app.set('view-engine', 'ejs');

app.get('/',(req, res)=>{
    res.render('../client/views/index.ejs');
});

app.use('/static', Express.static('public'));

app.listen(8081, function(){
    console.log('App listening!');
});
开发者ID:FChapeau,项目名称:Hokage,代码行数:19,代码来源:server.ts

示例8: express

// Imports
	import * as express from 'express';
	import * as path from 'path';
	import {config} from '../../config.ts';

// Server setup
	let serverConfig = config.servers.statics;
	export let server = express();

// Setup statics
	let filesPath = path.join(process.cwd(), 'src/setup/statics/files');
	server.use(config.httpRoutes.statics.path, express.static(filesPath));

// Start function
	export function startServer () {
		server.listen(serverConfig.port, function () {
			console.log('Serving statics at '+serverConfig.domain+':'+serverConfig.port);
		});
	}
开发者ID:dsilva2401,项目名称:server-seed,代码行数:19,代码来源:server.ts

示例9: async

export const bootstrapApp = async (): Promise<BootstrapSettings> => {
    /**
     * We create a new express server instance.
     */
    const app: express.Application = express();

    app.use(json({ limit: "50mb" }));
    app.use(urlencoded({ extended: true }));

    useExpressServer(app, {
        cors: true,
        routePrefix: env.app.routePrefix,
        defaultErrorHandler: false,
        classTransformer: true,
        validation: true,
        /**
         * We can add options about how routing-controllers should configure itself.
         * Here we specify what controllers should be registered in our express server.
         */
        controllers: env.app.dirs.controllers,
        middlewares: env.app.dirs.middlewares,
    });

    winston.configure({
        transports: [
            new winston.transports.Console({
                level: env.log.level,
                handleExceptions: true,
                json: env.log.json,
                timestamp: env.node !== "development",
                colorize: env.node === "development",
            }),
        ],
    });

    routingUseContainer(Container);
    ormUseContainer(Container);
    classValidatorUseContainer(Container);

    // Register validator schemes
    env.app.dirs.validatorSchemes.forEach((pattern) => {
        glob(pattern, (err: any, files: Array<string>) => {
            for (const file of files) {
                const schemas = require(file);

                Object.keys(schemas).forEach((key) => {
                    registerSchema(schemas[key]);
                });
            }
        });
    });
    env.app.dirs.subscribers.forEach((pattern) => {
        glob(pattern, (err: any, files: Array<string>) => {
            for (const file of files) {
                require(file);
            }
        });
    });

    const initTypeORM = async () => {
        const loadedConnectionOptions = await getConnectionOptions();

        const connectionOptions = Object.assign(loadedConnectionOptions, {
            type: env.db.type as any, // See createConnection options for valid types
            host: env.db.host,
            port: env.db.port,
            username: env.db.username,
            password: env.db.password,
            database: env.db.database,
            synchronize: env.db.synchronize,
            logging: env.db.logging,
            entities: env.app.dirs.entities,
            migrations: env.app.dirs.migrations,
        });

        return createConnection(connectionOptions);
    };

    app.get(
        env.app.routePrefix,
        (req: express.Request, res: express.Response) => {
            return res.json({
                name: env.app.name,
                version: env.app.version,
                description: env.app.description,
            });
        },
    );

    const log = new Logger(__filename);

    try {
        const connection = await initTypeORM();

        const server: http.Server = app.listen(env.app.port);

        banner(log);

        return {
            app,
//.........这里部分代码省略.........
开发者ID:LogansUA,项目名称:jest-import-error,代码行数:101,代码来源:bootstrap.ts

示例10: it

      it("returns a resolved promise", () => {
        const setupProxyServer = (provider as any).setupProxyServer
        const app = express()

        expect(setupProxyServer(app)).to.be.an.instanceOf(http.Server)
      })
开发者ID:pact-foundation,项目名称:pact-js,代码行数:6,代码来源:messageProviderPact.spec.ts


注:本文中的express类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。