• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript express-history-api-fallback类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中express-history-api-fallback的典型用法代码示例。如果您正苦于以下问题:TypeScript express-history-api-fallback类的具体用法?TypeScript express-history-api-fallback怎么用?TypeScript express-history-api-fallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了express-history-api-fallback类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: Promise

 server(port: number, dir: string) {
   let app = express();
   let root = resolve(process.cwd(), dir);
   app.use(express.static(root));
   app.use(history('index.html', { root }));
   return new Promise((resolve, reject) => {
     let server = app.listen(port, () => {
       resolve(server);
     });
   });
 }
开发者ID:onpoc,项目名称:onpoc.github.io,代码行数:11,代码来源:e2e.ts


示例2: serveProd

export function serveProd() {
  let root = resolve(process.cwd(), PROD_DEST);
  let server = express();

  server.use(APP_BASE, serveStatic(root));

  server.use(fallback('index.html', { root }));

  server.listen(PORT, () =>
    openResource('http://localhost:' + PORT + APP_BASE)
  );
};
开发者ID:Amoghavarsha,项目名称:angular2-seed,代码行数:12,代码来源:server.ts


示例3: serveProd

export function serveProd() {
  let root = resolve(process.cwd(), Config.PROD_DEST);
  let server = express();
  let compression = require('compression');
      server.use(compression());

  server.use(Config.APP_BASE, express.static(root));

  server.use(fallback('index.html', { root }));

  server.listen(Config.PORT, () =>
    openResource('http://localhost:' + Config.PORT + Config.APP_BASE)
  );
};
开发者ID:Sjiep,项目名称:angular2-seed,代码行数:14,代码来源:server.ts


示例4: Promise

 server(port: number, dir: string) {
   const app = express();
   const root = resolve(process.cwd(), dir);
   for (const proxy of Config.PROXY_MIDDLEWARE) {
     app.use(proxy);
   }
   app.use(Config.APP_BASE, express.static(root));
   app.use(history('index.html', {root}));
   return new Promise((resolve) => {
     const server = app.listen(port, () => {
       resolve(server);
     });
   });
 }
开发者ID:NickyDo,项目名称:angular-seed-1,代码行数:14,代码来源:e2e.ts


示例5: serveProd

export function serveProd() {
  let root = resolve(process.cwd(), Config.PROD_DEST);
  let server = express();

  for (let proxy of Config.getProxyMiddleware()) {
    server.use(proxy);
  }

  server.use(Config.APP_BASE, express.static(root));

  server.use(fallback('index.html', { root }));

  server.listen(Config.PORT, () =>
    openResource('http://localhost:' + Config.PORT + Config.APP_BASE)
  );
};
开发者ID:GoEngin,项目名称:GoEngin,代码行数:16,代码来源:server.ts


示例6: serveProd

export function serveProd() {
  let root = resolve(process.cwd(), PROD_DEST);
  let app = express();

  app.use(bodyParser.json()); 

  app.use(passport.initialize());
  //app.use(passport.session()); 

  let compression = require('compression');
      app.use(compression());

  mongoose.connect('mongodb://admin:[email protected]:39705/fcc-polling-app'); // Connect to MongoDB database for polling app.  
  //mongoose.connect('mongodb://localhost:27017/pollingDB'); // Connect to MongoDB database for polling app.  

  // Make sure mongod is running! If not, log an error and exit. 

  mongoose.connection.on('error', function() {
    console.log('MongoDB Connection Error. Please make sure that MongoDB is running.');
    process.exit(1);
  });

  //app.use(session({ secret: 'my_precious_l@3' }));
  app.use(session({ 
    secret: 'my_precious_l@3', 
    cookie: { maxAge: 60000 },
    saveUninitialized: false, // don't create session until something stored 
    resave: false, //don't save session if unmodified     
    store: new MongoStore({ mongooseConnection: mongoose.connection })
  })); 

  // ********** API ROUTES **************************
  // BEGIN API ROUTES

  app.get('/api', function(req, res) {
      return res.send('Default API route...');
  });

  // -------------- POLLS ROUTES --------------------
  app.get('/api/polls', function(req, res) {
    Poll.find({}, function (err, polls) {
        res.json(polls);
    });   
  });  

  //server.get('/api/items', pollsController.getAllPolls); // Handle GET request at /polls endpoint to retrieve all the polls

  app.post('/api/polls', function(req, res) {
    // Create a new poll

    let poll = new Poll({
      name: req.body.name,
      creatorId: req.body.creatorId,
      options: req.body.options
    });

    poll.save(function (err, poll) {
      if (err) { 
        console.log('error saving poll: ', err);
      }
      res.status(201).json(poll);
    });

  });

  app.get('/api/polls/:id', function(req, res) {
    let id = req.params.id;
    Poll.findOne({'_id':id},function(err, result) {
      return res.send(result);
    });             
  });

  app.put('/api/polls/:id', function(req, res) {
    //let id = req.params.id;
    //console.log('Will update poll with id of: ', id);

    let poll = req.body;
    let id = poll._id;

    delete poll._id;

    if (id) {
        Poll.update({_id: id}, poll, {upsert: true}, function (err, poll) {
          //res.json(poll);
          Poll.findOne({'_id':id},function(err, result) {
            return res.send(result);
          });           
        });
    }    
   
  });

  app.delete('/api/polls/:id', function(req, res) {
    //return res.send('API Route to DELETE a poll with id of: ' + req.params.id);
    let id = req.params.id;
    Poll.remove({'_id': id},function(result) {
      Poll.find({}, function (err, polls) {
          res.json(polls);
      });      
    });    
//.........这里部分代码省略.........
开发者ID:dlwebdev,项目名称:angular2-seed,代码行数:101,代码来源:server.ts



注:本文中的express-history-api-fallback类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript express-jwt类代码示例发布时间:2022-05-28
下一篇:
TypeScript express-handlebars类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap