本文整理汇总了TypeScript中express-serve-static-core.Express.use方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Express.use方法的具体用法?TypeScript Express.use怎么用?TypeScript Express.use使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类express-serve-static-core.Express
的用法示例。
在下文中一共展示了Express.use方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: configureRoutes
export function configureRoutes(app: Express): void{
let rootPath: string = path.join(__dirname, '../public');
app.use( express.static(rootPath) );
let servePath: string = path.join(__dirname, '../public/views');
app.use( express.static(servePath) );
setDummyRouting(app);
}
示例2: configure
private static configure(app: Express, server:Server) {
app.use((req:Request, res:Response, next:NextFunction) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
app.use(bodyParser.json());
app.use(express.static('public'));
let repository = new ReportsRepository();
let routes = ReportRoutes(repository);
app.use('/api/reports', routes);
app.get('/*', (req:Request, res:Response) => {
res.sendfile('./public/index.html');
});
let tickerService = new TickerService(server, repository);
tickerService.listen();
}
示例3: setDummyRouting
function setDummyRouting(app: Express){
let dummyRouter: Router = Router();
let dummyServePath: string = path.join(__dirname, '../public/views/dummy');
dummyRouter.use( express.static(dummyServePath) );
dummyRouter.get('/test', function(req : Request, res: Response){
res.send(dummy.getDummyMessage());
})
dummyRouter.get('/forajax', function(req : Request, res: Response){
res.send('This was retrieved through ajax!');
})
app.use('/dummy/', dummyRouter);
}
示例4: express
import * as express from "express";
import {Express} from "express-serve-static-core";
import * as cors from "cors";
export let app: Express = express();
app.use(cors());
export default app;