本文整理匯總了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(); });
}
示例2: Run
export function Run():void{
var app = express();
app.listen(3000,()=>{
console.log("server start at localhost:3000");
})
}
示例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('/')
示例4: express
import { SetupRouter } from './routes/setup-router';
import * as express from 'express';
var server = express();
SetupRouter(server);
server.listen(3000, () => {
console.log("listeninig");
});
示例5: constructor
constructor() {
this.app = express();
this.config();
this.routes();
}
示例6: constructor
constructor() {
this.expressApp = express();
}
示例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/");
示例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) {
示例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))
示例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)
});
});
}