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


TypeScript Express.set方法代码示例

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


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

示例1: initRoutes

export async function initRoutes(app: Express) {
  console.log('Init routes...');

  app.set('trust proxy', 'loopback');
  app.use(compression());
  app.use(bodyParser.json());

  await db.init();
  stats.init();

  app.post('/vote', (req, res) => {
    const vote: Vote = req.body;
    if (isVoteValid(vote)) {
      stats.addVote(vote);
      db.saveVote(extend(vote, {
        date: new Date(),
        ip: req.ip,
        userAgent: req.get('User-Agent')
      })).then(oldVote => {
        if (oldVote) {
          stats.removeVote(oldVote);
        }
      });
    } else {
      console.log('Invalid vote', vote);
    }
    res.json({});
  });

  app.get('/stats', (_req, res) => {
    res.set('Cache-Control', 'max-age=' + 1);
    res.json(stats.getStats());
  });

  app.use(express.static('public'));

  app.set('views', './server/views');
  app.engine('handlebars', exphbs({ defaultLayout: 'main' }));
  app.set('view engine', 'handlebars');

  app.get(/^\/$|\/index.html/, (req, res) => {
    renderWithClientToken('index', req, res);
  });

  app.get('/iframe.html', (req, res) => {
    renderWithClientToken('iframe', req, res);
  });

};
开发者ID:shybyte,项目名称:wahlomat,代码行数:49,代码来源:routes.ts

示例2:

const applyApiMocks = (app: Express) => {
    app.set('json spaces', 40);

    app.get(path.resolve(CONFIG.API_PREFIX, 'title'), (request, response) =>
        response.json({
            data: appConstants.APP_TITLE,
        }),
    );
};
开发者ID:athrunsun,项目名称:oh-my-stars,代码行数:9,代码来源:apiMock.ts

示例3: function

app.on('ready', function() {

	var ifaces = os.networkInterfaces();
	Object.keys(ifaces).forEach(function (ifname) {
		if(host_url){
			return true;
		}
		ifaces[ifname].forEach(function (iface) {
			if(host_url){
				return true;
			}
			if ('IPv4' !== iface.family || iface.internal !== false) {
				// skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
				return;
			}
			if(!host_url){
				host_url = "http://"+iface.address+":"+PORT+"/";
			}
		});
	});

	mainWindow = electronWindow.createWindow({width: 800, height: 600});
	mainWindow.showUrl(path.resolve(path_to_root, 'index.html'), {
		'role_url': host_url
	}, () => {
		console.log('window is now visible!');
		//mainWindow.webContents.openDevTools();
	});

	mainWindow.on('closed', function () {
		mainWindow = null; // let GC run its course
	});

	//Staic file server
	server = express();
	server.use(compression());
	if(MINIFY_ASSETS) {
		server.use(minify());
	}
	server.use(express.static(path.join(path_to_root, 'assets'), { maxAge: 1000*60*60*24*7 }));
	server.use(express.static(path.join(path_to_root, 'generated')));
	server.set('view engine', 'ejs');

	server.get('/', function(req, res){
		res.render('index', {title: 'Title data', role: 'list'});
	});

	server.get('/:role', function(req, res, next){
		let role = req.params.role;
		res.render(role, {role: role}, function(err, html) {
			if (!err) {
				return res.send(html);
			} else {
				// Not a view, skip this resolver
				next();
			}
		});
	});

	//Start server
	let httpServer = http.createServer(server);
	httpServer.listen(PORT, function(){
		// Print out our actual IP Address so they know what to tell their friends :D
		console.log("Listening on "+host_url);
	});

	game = new Game();
	game.net = new ServerNet(game, httpServer);
	game.initShip('ship1');

	if(DEV && os.platform() !== 'win32') {
		let replInstance = repl.start({'prompt': 'node> '});
		replInstance.on('exit', () => {
			app.quit();
		});
		replInstance.context.game = game;
		replInstance.context.server = server;
	}
});
开发者ID:Nebual,项目名称:space-couch,代码行数:79,代码来源:server.ts

示例4: request

import {NextFunction} from "express";
import {Response} from "express";
import {Request} from "express";
import {Express} from "express";
import {HttpError} from "http-errors";

request("http://api.factoriomods.com/mods", function(err: Error, res: Response, body: string) {
    let mods = JSON.parse(body);
    mods.sort((a, b) => { if (a.id > b.id) { return 1; } else if (a.id < b.id) { return -1; } else { return 0; } })
        .forEach((mod) => { console.log(Mod.parseFromJson(JSON.stringify((mod)))); });
});

let app: Express = express();

// view engine setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "jade");

// uncomment after placing your favicon in /public
// app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));

app.use("/", index.router);
app.use("/users", users.router);

// catch 404 and forward to error handler
app.use(function(req: Request, res: Response, next: NextFunction) {
开发者ID:phroph,项目名称:node-factorio-launcher,代码行数:31,代码来源:app.ts


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