当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript express-history-api-fallback.default方法代码示例

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


在下文中一共展示了express-history-api-fallback.default方法的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:admin@ds139705.mlab.com: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.default方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。