本文整理汇总了TypeScript中serve-static.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: registerView
registerView() {
// all environments
this.app.set('port', HTTP_PORT);
this.app.set('view engine', 'ejs');
this.app.use('/static', serveStatic(__dirname + '/../static'));
this.app.use(serveStatic(__dirname + '/../publish'));
this.app.use(serveStatic(__dirname + '/../lib'));
// http://stackoverflow.com/questions/12488930/dump-an-object-in-ejs-templates-from-express3-x-views
this.app.locals.inspect = require('util').inspect;
this.app.get('/', (req, res) => {
res.render('pages/index');
});
this.app.get('/game', (req, res) => {
res.render('pages/game');
});
this.app.get('/single', (req, res) => {
res.render('pages/single');
});
this.app.get('/admin', (req, res) => {
res.render('pages/admin', {
world: this.world,
connMgr: this.connMgr,
helper: new AdminHelper()
});
});
}
示例2: function
module.exports = function(ROOT) {
var app = express();
var {expressEngine} = require('angular2-universal-preview');
// rendering engine
app.engine('ng2.html', expressEngine);
app.set('views', path.join(ROOT));
app.set('view engine', 'ng2.html');
app.set('view options', { doctype: 'html' });
app.set('json spaces', 2);
var routes = require('./routes');
var api = require('./api');
var graphApi = require('./graph_api');
app.use(serveStatic(path.join(ROOT, 'dist'), {index: false}));
app.use(serveStatic(path.join(ROOT, 'public'), {index: false}));
app.use('/api', api(ROOT));
app.use('/graph_api', api(ROOT));
app.use(routes(ROOT));
app.use(morgan('dev'));
app.get('*', function(req, res) {
res.json({
'url': req.originalUrl,
'route': 'Sorry this page does not exist!'
});
});
return app;
};
示例3: function
const initializeServer = function() {
const favicon = require("serve-favicon");
const serveStatic = require("serve-static");
const winston = require("winston");
const expressWinston = require("express-winston");
const loggerSettings = {
transports: [
new winston.transports.Console({
level: "error",
json: true,
colorize: true,
}),
],
};
const prefix: string = staticFolder + "-" + serverConfig.MATH_PROGRAM + "/";
const getList: reader.GetListFunction = reader.tutorialReader(prefix, fs);
const admin = require("./admin")(clients, serverConfig.MATH_PROGRAM);
app.use(favicon(staticFolder + "-" +
serverConfig.MATH_PROGRAM + "/favicon.ico"));
app.use(SocketIOFileUpload.router);
app.use(serveStatic(staticFolder + "-" + serverConfig.MATH_PROGRAM));
app.use(serveStatic(staticFolder + "-common"));
app.use(expressWinston.logger(loggerSettings));
app.use("/admin", admin.stats);
app.use("/getListOfTutorials", getList);
app.use(unhandled);
};
示例4: function
module.exports = function(ROOT) {
var app = express();
var {ng2engine} = require('angular2-universal-preview');
// rendering engine
app.engine('ng2.html', ng2engine);
app.set('views', path.join(ROOT, 'examples'));
app.set('view engine', 'ng2.html');
app.set('view options', { doctype: 'html' });
var routes = require('./routes');
var api = require('./api');
var graphApi = require('./graph_api');
app.use(serveStatic(`${ROOT}/dist`));
app.use(serveStatic(`${ROOT}/examples/app/public`));
app.use('/api', api(ROOT));
app.use('/graph_api', api(ROOT));
app.use(routes(ROOT));
app.use(morgan('dev'));
app.get('*', function(req, res) {
res.json({
'route': 'Sorry this page does not exist!'
});
});
return app;
};
示例5: start
export function start(port?:number,plugins?:Array<any>):void
{
var httpPort = port;
if(!httpPort || httpPort === 0)
{
httpPort = 3000;
}
var app = connect();
if(plugins)
{
plugins.forEach((plugin)=>{
app.use(plugin);
})
}
if(env === "development")
{
app.use(serveStatic(staticPath,{'index': ['src/client/index.html']}))
}
else
{
staticPath = path.resolve("./dist/src/client");
app.use(serveStatic(staticPath))
}
server = http.createServer(app).listen(httpPort);
// Maintain a hash of all connected sockets
var sockets = {}, nextSocketId = 0;
server.on('connection', function (socket) {
// Add a newly connected socket
var socketId = nextSocketId++;
sockets[socketId] = socket;
// Remove the socket when it closes
socket.on('close', function () {
delete sockets[socketId];
});
});
console.log("Server started");
return server;
}
示例6: setPageRoutes
export function setPageRoutes(app: express.Application): void {
// Sets up the favicon
app.use(favicon(config.server.staticFolder + '/favicon.ico'));
// First looks for a static file: index.html, css, images, etc.
app.use(config.server.staticUrl, compress());
app.use(config.server.staticUrl, static(config.server.staticFolder));
app.use(config.server.staticUrl, (req: express.Request, res: express.Response, next: (err?: any) => void) => {
res.send(404);
});
}
示例7: Config
constructor() {
this.configChangedCallback = this.configChanged;
this.config = new Config(this.configChangedCallback.bind(this));
//Using connect
this.app = connect()
.use(favicon(__dirname + '/pub/images/favicon.ico'))
.use('/admin', connect_static(__dirname + '/pub', {fallthrough: false}))
.use(bodyParser.json({ type: '*/*' }))
.use(
function(req:any, res: any) {
try {
console.log(req.body);
res.setHeader('Content-Type', 'application/json');
//Do logic
let commands = req.body["commands"];
//Hard coded for testing purposes
let ccCommand = commands[0];
let c: Color = new Color(ccCommand.color);
let result = {
"color":{
R: c.getByteArray()[0],
G: c.getByteArray()[1],
B: c.getByteArray()[2]
}
};
//response.end('Setting color to ' + c.toString());
res.end(JSON.stringify(result, null, 2));
}
catch (Error) {
console.error(Error.stack);
}
})
.listen(1234, function() {
console.log("Listening on port 1234...");
})
//Listen to EADDRINUSE (port already in use)
.on('error', (function(err: any) {
if (err.code === "EADDRINUSE") {
console.log("Port already in use. Retrying in "+this.config.getTimeout()+" seconds...");
setTimeout((function() {
this.startListening();
}).bind(this), this.config.getTimeout() * 1000);
}
}).bind(this));
}
示例8: showApp
function showApp() {
var serve = serveStatic(app, {'index': ['index.html', 'index.htm']});
appServer = http.createServer(function(req, res){
var done = finalhandler(req, res);
serve(req, res, done);
});
appServer.listen(8888, function () {
console.log('Serving ' + app + ' on http://localhost:8888')
})
}
示例9: setupMiddleware
public setupMiddleware(): server {
const proxyOptions: ProxyOption = url.parse( 'http://' + this.option.remoteAddr );
proxyOptions.preserveHost = true;
proxyOptions.headers = {host: this.option.host};
this.app.use((req:http.IncomingMessage,res:http.ServerResponse,next:Function)=>{
this.option.logger.request(req,res);
next();
} );
this.app.use( '/api/recotw', proxy( proxyOptions ) );
this.app.use( serveStatic( this.option.root ) );
return this;
}
示例10: testBlockMap
function testBlockMap(oldDir: string, newDir: string) {
const serveStatic = require("serve-static")
const finalHandler = require("finalhandler")
const serve = serveStatic(newDir)
{
(process as any).resourcesPath = path.join(oldDir, "win-unpacked", "resources")
}
const server = createServer((request, response) => {
serve(request, response, finalHandler(request, response))
})
const mockApp = createTestApp("0.0.1")
jest.mock("electron", () => {
return {
app: mockApp,
}
}, {virtual: true})
return new BluebirdPromise((resolve, reject) => {
server.on("error", reject)
server!!.listen(0, "127.0.0.1", 16, () => {
const updater = new NsisUpdater()
tuneNsisUpdater(updater)
updater.logger = console
const doTest = async () => {
const address = server!!.address()
updater.updateConfigPath = await writeUpdateConfig<GenericServerOptions>({
provider: "generic",
url: `http://${address.address}:${address.port}`,
})
await checkResult(updater)
}
doTest()
.then(() => resolve())
.catch(reject)
})
})
.finally(() => {
server.close()
})
}