本文整理匯總了TypeScript中express-serve-static-core.Express類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Express類的具體用法?TypeScript Express怎麽用?TypeScript Express使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Express類的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;