當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript express-history-api-fallback類代碼示例

本文整理匯總了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: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類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。