本文整理汇总了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('./')
}));
}
示例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);
});
});
}
示例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);
});
});
}
示例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);
});
示例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);
});
示例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