本文整理汇总了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);
});
});
}
示例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)
);
};
示例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)
);
};
示例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);
});
});
}
示例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)
);
};
示例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);
});
});
//.........这里部分代码省略.........