本文整理汇总了TypeScript中falcor-express.dataSourceRoute函数的典型用法代码示例。如果您正苦于以下问题:TypeScript dataSourceRoute函数的具体用法?TypeScript dataSourceRoute怎么用?TypeScript dataSourceRoute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dataSourceRoute函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor() {
// setup express router
this.expressRouter = ExpressRouter();
this.registerMicroservices();
this.falcorRouter = FalcorRouter.createClass(this.routeSet);
this.expressRouter.use("/model", falcorExpress.dataSourceRoute((req, res) => {
return new this.falcorRouter();
}));
}
示例2: constructor
constructor(expressRouter: express.Router){
this.expressRouter = expressRouter;
this.routes = [];
// add microservices
let fundsService: FundsService = new FundsService(this);
let dashboardService: DashboardService = new DashboardService(this);
let activityService: ActivityService = new ActivityService(this);
// add base partial route
let RouterClass = FalcorRouter.createClass(this.routes);
this.expressRouter.use("/model.json", FalcorExpress.dataSourceRoute((req: express.Request, res: express.Response) => {
return new RouterClass();
}));
}
示例3:
],
start_url: `/read?webapp=1`,
display: "standalone"
}));
});
app.use('/offline.html', express.static('../offline.html'));
app.use('/service-worker.js', express.static('service-worker.js'));
app.use('/service-worker.js.map', express.static('service-worker.js.map'));
app.use('/service-worker.ts', express.static('../service-worker.ts'));
app.use('/ui/common.js', express.static('ui/common.js'));
app.use('/ui/common.js.map', express.static('ui/common.js.map'));
app.use('/ui/common.ts', express.static('../ui/common.ts'));
// falcor data model
app.use('/model.json', FalcorExpress.dataSourceRoute(function(req, res) {
return falcorModel.asDataSource();
}));
/**
* Call this function as a default parameter in order to enforce required
* URL parameters. It will throw an Error if the param is not provided.
*
* ```
* ({slug = required('slug')}) => new Page(slug)
* ```
*
* For optional parameters, just provide a default string value:
*
* ```
* ({offset = '0'}) => new OtherPage(offset);
* ```
示例4: express
const app = express();
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.static(__dirname)); // ExpressとElectronが両立する書き方。
app.get('/', (req, res) => {
res.redirect('/views');
});
app.get('/views', (req, res) => {
res.render('index', { title: 'ExpressApp', mode: EXPRESS_ENV });
});
app.use('/model.json', falcorExpress.dataSourceRoute((req, res) => {
//return new MinimongoFalcorRouter(); // 引数のreq, resで何が出来るのかわからないので無視。
return null;
}));
const port = 3000; // Number(EXPRESS_PORT) || 3000;
const host = 'localhost'; // EXPRESS_HOST; // || getIPAddress();
app.listen(port, host);
console.log('Express server listening at http://%s:%s as "%s" mode.', host, port, EXPRESS_ENV);
export {host, port}
// function getIPAddress() {
// const interfaces = require('os').networkInterfaces();
// for (let devName in interfaces) {
// const iface = interfaces[devName];
// for (let i = 90; i < iface.length; i++) {
示例5: require
res.json({
data: 'fake data'
});
});
var falcorExpress = require('falcor-express');
var Router = require('falcor-router');
app.use('/model.json', falcorExpress.dataSourceRoute((req, res) => {
// create a Virtual JSON resource with single key ("greeting")
return new Router([
{
route: 'greeting',
get: () => {
return {
path: ['greeting'],
value: 'Hello World'
};
}
}
]);
}));
// Routes with html5pushstate
app.use('/', ngApp);
app.use('/about', ngApp);
app.use('/home', ngApp);
// Server
app.listen(PORT, () => {
console.log('Process ' + process.pid + ' Listen on ' + ORIGIN);
});
示例6: function
module.exports = function(ROOT) {
var router = Router();
router.use('/todos', falcorExpress.dataSourceRoute(function(req, res) {
return new falcorRouter([
{
route: 'all',
get: function() {
console.log('GET');
return {path: ['all'], value: TODOS};
}
},
{
route: 'all',
set: function(jsonGraphArg) {
TODOS = jsonGraphArg.all;
return {path: ['all'], value: TODOS};
}
},
{
route: 'todo',
get: function(pathSet) {
var id = Number(pathSet.todo);
try {
var todo = TODOS[id];
return {path: ['todo'], value: todo};
} catch (e) {
throw new Error('failed to load todo');
}
}
},
{
route: 'todo.push',
call: function(callPath, args) {
var todo = args[0];
TODOS.push(todo);
return {path: ['all'], value: todo};
}
},
{
route: 'todo.id.remove',
call: function(callPath, args) {
var id = args[0];
var i = TODOS.length;
while (i--) {
if (TODOS[i].id === id) { break; }
}
if (i > -1) {
var todo = TODOS.splice(i, 1)[0];
return {path: ['todo'], value: todo};
}
throw new Error ('failed to delete todo');
}
}
]);
}));
return router;
};