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


TypeScript express.default方法代码示例

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


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

示例1: start

export default function start(serverDataPath: string) {
  dataPath = serverDataPath;
  SupCore.log(`Using data from ${dataPath}.`);
  process.on("uncaughtException", onUncaughtException);

  loadConfig();

  const { version, superpowers: { appApiVersion: appApiVersion } } = JSON.parse(fs.readFileSync(`${__dirname}/../../package.json`, { encoding: "utf8" }));
  SupCore.log(`Server v${version} starting...`);
  fs.writeFileSync(`${__dirname}/../../public/superpowers.json`, JSON.stringify({ version, appApiVersion, hasPassword: config.server.password.length !== 0 }, null, 2));

  // SupCore
  (global as any).SupCore = SupCore;
  SupCore.systemsPath = path.join(dataPath, "systems");

  // List available languages
  languageIds = fs.readdirSync(`${__dirname}/../../public/locales`);
  languageIds.unshift("none");

  // Main HTTP server
  mainApp = express();

  mainApp.use(cookieParser());
  mainApp.use(handleLanguage);

  mainApp.get("/", (req, res) => { res.redirect("/hub"); });
  mainApp.get("/login", serveLoginIndex);
  mainApp.get("/hub", enforceAuth, serveHubIndex);
  mainApp.get("/project", enforceAuth, serveProjectIndex);

  mainApp.use("/projects/:projectId/*", serveProjectWildcard);
  mainApp.use("/", express.static(`${__dirname}/../../public`));

  mainHttpServer = http.createServer(mainApp);
  mainHttpServer.on("error", onHttpServerError.bind(null, config.server.mainPort));

  io = socketio(mainHttpServer, { transports: [ "websocket" ] });

  // Build HTTP server
  buildApp = express();

  buildApp.get("/", redirectToHub);
  buildApp.get("/systems/:systemId/SupCore.js", serveSystemSupCore);

  buildApp.use("/", express.static(`${__dirname}/../../public`));

  buildApp.get("/builds/:projectId/:buildId/*", (req, res) => {
    const projectServer = hub.serversById[req.params.projectId];
    if (projectServer == null) { res.status(404).end("No such project"); return; }
    let buildId = req.params.buildId as string;
    if (buildId === "latest") buildId = (projectServer.nextBuildId - 1).toString();
    res.sendFile(path.join(projectServer.buildsPath, buildId, req.params[0]));
  });

  buildHttpServer = http.createServer(buildApp);
  buildHttpServer.on("error", onHttpServerError.bind(null, config.server.buildPort));

  loadSystems(mainApp, buildApp, onSystemsLoaded);

  // Save on exit and handle crashes
  process.on("SIGINT", onExit);
  process.on("message", (msg: string) => { if (msg === "stop") onExit(); });
}
开发者ID:fulopm,项目名称:superpowers-core,代码行数:63,代码来源:start.ts

示例2: Run

export function Run():void{
        var app = express();
        app.listen(3000,()=>{
            console.log("server start at localhost:3000");
        })
    }
开发者ID:ricoThink-R,项目名称:SuperPortal,代码行数:6,代码来源:server.ts

示例3: express

 */

import { expect } from 'chai';
import * as Q from 'q';
import * as express from 'express';
import { Response } from 'express';
import * as supertest from 'supertest';

import { AppSettings } from '../../../common/models/index';
import { PivotRequest } from '../../utils/index';

import { AppSettingsMock } from '../../../common/models/app-settings/app-settings.mock';

import * as pivotRouter from './pivot';

var app = express();

var appSettings: AppSettings = AppSettingsMock.wikiOnlyWithExecutor();
app.use((req: PivotRequest, res: Response, next: Function) => {
  req.user = null;
  req.version = '0.9.4';
  req.getSettings = (dataSourceOfInterest?: string) => Q(appSettings);
  next();
});

app.use('/', pivotRouter);

describe('pivot router', () => {
  it('does a query (value)', (testComplete) => {
    supertest(app)
      .get('/')
开发者ID:RaviNK,项目名称:pivot,代码行数:31,代码来源:pivot.mocha.ts

示例4: express

import { SetupRouter } from './routes/setup-router';
import * as express from 'express';

var server = express();

SetupRouter(server);

server.listen(3000, () => {
    console.log("listeninig");
});
开发者ID:c4wrd,项目名称:typescript-express-seed,代码行数:10,代码来源:index.ts

示例5: constructor

 constructor() {
   this.app = express();
   this.config();
   this.routes();
 }
开发者ID:HaoranYi,项目名称:gitProj,代码行数:5,代码来源:app.ts

示例6: constructor

 constructor() {
   this.expressApp = express();
 }
开发者ID:douglascvas,项目名称:springify,代码行数:3,代码来源:TestApplication.ts

示例7: require

import "reflect-metadata";
import * as express from "express";
import {useExpressServer} from "../../src/index";
import "./BlogController"; // this can be require("./BlogController") actually

let app = express(); // create express server
useExpressServer(app); // register controllers routes in our express application
// controllerRunner.isLogErrorsEnabled = true; // enable error logging of exception error into console
// controllerRunner.isStackTraceEnabled = true; // enable adding of stack trace to response message

app.listen(3001); // run express app

console.log("Express server is running on port 3001. Open http://localhost:3001/blogs/");
开发者ID:MrDataScientist,项目名称:routing-controllers,代码行数:13,代码来源:app.ts

示例8: express

/// <reference path="_all.d.ts" />

import * as express from "express";
import { join } from "path";
import * as favicon from "serve-favicon";
import * as logger from "morgan";
import { json, urlencoded } from "body-parser";

import { indexRouter } from "./routes/index-router";

const app: express.Application = express();
app.disable("x-powered-by");

app.use(favicon(join(__dirname, "./public", "favicon.ico")));
app.use(express.static(join(__dirname, "../public")));

app.use(logger("dev"));
app.use(json());
app.use(urlencoded({ extended: true }));

// api routes
app.use("/", indexRouter);

// error handlers
// development error handler
// will print stacktrace
if (app.get("env") === "development") {

    app.use(express.static(join(__dirname, "../node_modules")));

    app.use(function(err: any, req: express.Request, res: express.Response, next: express.NextFunction) {
开发者ID:jrjuniorsp,项目名称:express4-typescript-api-starter,代码行数:31,代码来源:app.ts

示例9: startApp

    )
    process.exit(1)
    return
  }

  runningApp.on('close', () => {
    process.exit(0)
  })
}

if (process.env.NODE_ENV === 'production') {
  startApp()
} else {
  const rendererConfig = configs[1]

  const server = express()
  const compiler = webpack(rendererConfig)
  const port = getPortOrDefault()

  const message = 'Could not find public path from configuration'
  server.use(
    devMiddleware(compiler, {
      publicPath: u(
        message,
        u(message, u(message, rendererConfig).output).publicPath
      ),
      logLevel: 'error',
    })
  )

  server.use(hotMiddleware(compiler))
开发者ID:ghmoore,项目名称:desktop,代码行数:31,代码来源:start.ts

示例10: constructor

    constructor(private port: number, dataService?: DatabaseService) {
        this.config = readConfigFile();
        this.app = express();

        this.server = http.createServer(this.app);
        this.server.listen(port);

        this.dataService = dataService || new DatabaseService();
        this.socket = new PointSocket(this.server);

        this.app.use(bodyParser.json());

        this.app.use(bodyParser.urlencoded({
            extended: true
        }));

        this.app.use(function(req, res, next) {
            res.header("Access-Control-Allow-Origin", "*");
            res.header("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS");
            res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
            next();
        });


        this.app.get('/api/points/', (req: any, res: any) => {
            this.dataService.getPoints()
                .then((points: Point[]) => {
                    res.json(points);
                })
                .catch((error: any) => {
                    this.errorHandler(error, res)
                });
        });

        this.app.post('/api/points/', (req: any, res: any) => {
            let point = req.body;
            this.dataService.savePoint(point)
                .then((point: Point) => {
                    this.socket.emitNewPoint(point);
                    res.json(point);
                })
                .catch((error: any) => {
                    this.errorHandler(error, res)
                });

        });

        this.app.get('/api/points/:id', (req: any, res: any) => {
            this.dataService.getPoint(req.params.id)
                .then((point: Point) => {
                    res.json(point);
                })
                .catch((error: any) => {
                    this.errorHandler(error, res)
                });
        });

        this.app.delete('/api/points/:id', (req: any, res: any) => {
            let removedPoint: Point;
            this.dataService.getPoint(req.params.id).then((point: Point) => {
                removedPoint = point;
                return this.dataService.removePoint(req.params.id)
            }).then((result: any) => {
                this.socket.emitRemovePoint(removedPoint);
                res.json(result.result);
            }).catch((error: any) => {
                this.errorHandler(error, res)
            });
        });

        this.app.put('/api/points/:id', (req: any, res: any) => {
            let pointUpdate = req.body;
            pointUpdate._id = req.params.id;
            this.dataService.updatePoint(pointUpdate)
                .then((point: any) => {
                    this.socket.emitUpdatePoint(point);
                    res.json(point);
                })
                .catch((error: any) => {
                    this.errorHandler(error, res)
                });
        });
    }
开发者ID:najor,项目名称:ng2-md-arcgis,代码行数:83,代码来源:server.ts


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