當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。