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


TypeScript restify.serveStatic函数代码示例

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


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

示例1: constructor

	constructor(server: Server) {
		server.get('/', serveStatic({
			directory: resolve('./public'),
			file: 'index.html'
		}));

		server.get(/\/__client__\/?.*/, serveStatic({
			directory: resolve('./')
		}));
	}
开发者ID:Ibanheiz,项目名称:tdc-rxjs-demo,代码行数:10,代码来源:Http.ts

示例2: serve

/**
 * Start the server and return its URL.
 */
function serve(log: (msg: any) => any): Promise<string> {
  let server = restify.createServer();
  let qp = restify.queryParser({ mapParams: false });

  // Log messages to a file.
  server.get('/log', qp, (req: any, res: any, next: any) => {
    let out = log(JSON.parse(req.query['msg']));
    res.send(out);
    return next();
  });

  // Serve the main HTML and JS files.
  server.get('/', restify.serveStatic({
    // `directory: '.'` appears to be broken:
    // https://github.com/restify/node-restify/issues/549
    directory: '../harness',
    file: 'index.html',
    maxAge: 0,
  }));
  server.get('/client.js', restify.serveStatic({
    directory: './build',
    file: 'client.js',
    maxAge: 0,
  }));

  // Serve the dingus assets.
  server.get(/\/.*/, restify.serveStatic({
    directory: '../dingus',
    default: 'index.html',
    maxAge: 0,
  }));

  // Show errors. This should be a Restify default.
  server.on('uncaughtException', (req: any, res: any, route: any, err: any) => {
    if (err.stack) {
      console.error(err.stack);
    } else {
      console.error(err);
    }
  });

  // More filling in the blanks: log each request as it comes in.
  server.on('after', (req: any, res: any, route: any, err: any) => {
    plog(res.statusCode + " " + req.method + " " + req.url);
  });

  // Start the server.
  let port = 4700;
  let url = "http://localhost:" + port;
  return new Promise((resolve, reject) => {
    server.listen(port, () => {
      resolve(url);
    });
  });
}
开发者ID:Microsoft,项目名称:staticstaging,代码行数:58,代码来源:harness.ts

示例3: serve

/**
 * Start the server and return its URL.
 */
function serve(log: (msg: any) => void): Promise<string> {
  let server = restify.createServer();
  let qp = restify.queryParser({ mapParams: false });

  // Log messages to a file.
  server.get('/log', qp, (req: any, res: any, next: any) => {
    log(JSON.parse(req.query['msg']));
    res.send('done');
    next();
  });

  // Serve the main HTML and JS files.
  server.get('/', restify.serveStatic({
    // `directory: '.'` appears to be broken:
    // https://github.com/restify/node-restify/issues/549
    directory: '../harness',
    file: 'index.html',
  }));
  server.get('/client.js', restify.serveStatic({
    directory: './build',
    file: 'client.js',
  }));

  // Serve the dingus assets.
  server.get(/\/.*/, restify.serveStatic({
    directory: '../dingus',
    default: 'index.html',
  }));

  // Start the server.
  let port = 4700;
  let url = "http://localhost:" + port;
  return new Promise((resolve, reject) => {
    server.listen(port, () => {
      resolve(url);
    });
  });
}
开发者ID:kleopatra999,项目名称:staticstaging,代码行数:41,代码来源:harness.ts

示例4: next

    }
    socket.emit("offer", { srcId: req.params.srcId, sdp: req.params.sdp });
    res.send(201);
    return next();
});

server.post("/api/answers", (req: restify.Request, res: restify.Response, next: restify.Next) => {
    let socket = sockets.get(req.params.targetId);
    if (socket == null) {
        res.send(404);
        return next();
    }
    socket.emit("offer", { sdp: req.params.sdp });
    res.send(201);
    return next();
});

server.get("/api/:name", (req: restify.Request, res: restify.Response, next: restify.Next) => {
    res.send(req.params);
    return next();
});

server.get(/\/?.*/, restify.serveStatic({
    directory: "./lib/public",
    default: "index.html"
}));

server.listen(3000, () => {
    console.log("%s listening at %s", server.name, server.url);
});
开发者ID:progre,项目名称:webrtctest,代码行数:30,代码来源:index.ts

示例5: next

        child_process.execFile(command, [option]);
        res.send("ok");
    } else {
        res.send("unsupported option");
    }
    next();
}

function add(req, res, next) {
    var path = root + "/" + req.query.path;
    console.log("adding " + path);
    child_process.execFile(command, ["-E", path]);
    res.send("ok");
    next();
}

var server = restify.createServer();
server.use(restify.queryParser());

server.get("/list", list);
server.get("/control", control);
server.get("/add", add);

server.get(/.*/, restify.serveStatic({
    directory: './client',
    default: 'index.html'
}));

server.listen(8080, () => {
    console.log("%s listening at %s", server.name, server.url);
});
开发者ID:knstvk,项目名称:remote,代码行数:31,代码来源:app.ts

示例6: serveStatic

  }
});
server.use(bodyParser());
server.use(CORS({}));
server.use(queryParser());


server.get('/swagger.json', serverController.getFixedSwaggerJson.bind(serverController));

// serve redirects
server.get(/^\/(a\/|avatar\/)/, redirectController.avatarRedirect.bind(redirectController));
server.get(/^\/(app|bm|it|ngh|start|two|cover|quotes|b\/|x\/)/, redirectController.redirect.bind(redirectController));

// serve public folder
server.get(/^(?!\/(book|info)).*/, serveStatic({
  directory: __dirname + '/public/',
  default: 'index.html'
}));

// API routes
server.get('/books', bsController.getAll.bind(bsController));
server.get('/books/search/:search', bsController.getAllBySearch.bind(bsController));
server.del('/books', bsController.reset.bind(bsController));
server.post('/book', bsController.create.bind(bsController));
server.post('/book/:isbn/rate', bsController.rate.bind(bsController));
server.get('/book/:isbn', bsController.getByISBN.bind(bsController));
server.get('/book/:isbn/check', bsController.checkISBN.bind(bsController));
server.put('/book/:isbn', bsController.update.bind(bsController));
server.del('/book/:isbn', bsController.delete.bind(bsController));
server.get('/info', serverController.info.bind(serverController));

// start server
开发者ID:Angular2Buch,项目名称:book-monkey2-api,代码行数:32,代码来源:server.ts


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