本文整理汇总了TypeScript中connect-livereload类的典型用法代码示例。如果您正苦于以下问题:TypeScript connect-livereload类的具体用法?TypeScript connect-livereload怎么用?TypeScript connect-livereload使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了connect-livereload类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: resolve
import * as connectLivereload from 'connect-livereload';
import * as express from 'express';
import * as bodyParser from 'body-parser';
import * as openResource from 'open';
import {resolve} from 'path';
import {APP_BASE, LIVE_RELOAD_PORT, PATH, PORT} from '../tools/config';
const INDEX_DEST_PATH = resolve(PATH.cwd, PATH.dest.app.base, 'index.html');
const server = express();
server.use(
APP_BASE,
connectLivereload({ port: LIVE_RELOAD_PORT })
);
server.use(express.static(PATH.dest.app.base));
server.use(bodyParser.json());
server.use(bodyParser.urlencoded({ extended: false }));
server.get('/api/**', (req, res, next) => {
// TODO: remove this. It just mimics a delay in the backend.
const delay = Math.floor((Math.random() * 300) + 1);
setTimeout(() => next(), delay);
});
server.get(APP_BASE + '*', (req, res) =>
res.sendFile(INDEX_DEST_PATH)
);
示例2: connect
/// <reference path="./connect-livereload.d.ts" />
import * as connect from "connect";
import * as livereload from "connect-livereload";
const app = connect();
// With no options
app.use(livereload());
// With string options
app.use(livereload({
port: 35729,
ignore: [".js", ".svg"]
}));
// With RegExp options
app.use(livereload({
port: 35729,
ignore: [/\.js(\?.*)?$/, /\.css(\?.*)?$/]
}));
// With default options
app.use(livereload({
ignore: [
/\.js(\?.*)?$/, /\.css(\?.*)?$/, /\.svg(\?.*)?$/, /\.ico(\?.*)?$/, /\.woff(\?.*)?$/,
/\.png(\?.*)?$/, /\.jpg(\?.*)?$/, /\.jpeg(\?.*)?$/, /\.gif(\?.*)?$/, /\.pdf(\?.*)?$/
],
// include all urls by default
include: [/.*/],
示例3: serveSPA
export function serveSPA() {
let server = express();
tinylr.listen(LIVE_RELOAD_PORT);
server.use(
APP_BASE,
connectLivereload({ port: LIVE_RELOAD_PORT }),
express.static(process.cwd())
);
server.listen(PORT, () =>
openResource('http://localhost:' + PORT + APP_BASE + APP_DEST)
);
}
示例4: serveSPA
export function serveSPA(env) {
let app = express();
app.use(
APP_BASE,
connectLivereload({port: LIVE_RELOAD_PORT}),
serveStatic(resolve(process.cwd(), PATH.dest[env].all))
);
app.all(APP_BASE + '*', (req, res) =>
res.sendFile(resolve(process.cwd(), PATH.dest[env].all, 'index.html'))
);
app.listen(PORT, () =>
openResource('http://localhost:' + PORT + APP_BASE)
);
}
示例5: serveSPA
export function serveSPA() {
let server = express();
tinylr.listen(LIVE_RELOAD_PORT);
server.use(
APP_BASE,
connectLivereload({ port: LIVE_RELOAD_PORT }),
serveStatic(resolve(process.cwd(), APP_DEST))
);
server.all(APP_BASE + '*', (req, res) =>
res.sendFile(resolve(process.cwd(), APP_DEST, 'index.html'))
);
server.listen(PORT, () =>
openResource('http://localhost:' + PORT + APP_BASE)
);
}
示例6: connectLivereload
}
};
let changed = files => {
if (!(files instanceof Array)) {
files = [files];
}
if (ENABLE_HOT_LOADING) {
ng2HotLoader.onChange(files);
} else {
tinylr.changed({
body: { files }
});
}
};
let tinylrMiddleware = connectLivereload({ port: LIVE_RELOAD_PORT });
let middleware = [
APP_BASE,
(req, res, next) => {
if (ENABLE_HOT_LOADING) {
next();
} else {
tinylrMiddleware(req, res, next);
}
},
express.static(process.cwd())
];
export { listen, changed, middleware };
示例7: express
let serveSPA = () => {
let server = express();
tinylr.listen(LIVE_RELOAD_PORT);
server.use(compression());
server.use(bodyParser.json());
server.get('/imageids', (req, res) => {
res.json({imageIds: randomImages.getIds()});
});
server.get('/lastmodified', (req, res) => {
res.json(lastModified);
});
server.get('/errorconfig', (req, res) => {
res.json(errorConfig);
});
/**
* Validates user submission and sends the message received via the contact from
*
* @param {Object} submission
* @param {string} submission.name
* @param {string} submission.email
* @param {string} submission.text
* @param {string} submission.heuning
*/
server.post('/send', (req, res) => {
let submission:Submission = req.body,
errors:Array<string> = mailHelper.validate(submission);
if (errors.length > 0) {
res.status(400).send({errors: errors});
} else {
let message:Message = mailHelper.buildMessage(submission),
messageCopy:Message = mailHelper.buildMessageCopy(submission);
nodeMailer.send(message, (success:boolean) => {
if (success) {
nodeMailer.send(messageCopy, (success:boolean) => {
if (success) {
res.status(200).json('Sent successfully');
} else {
res.sendStatus(500);
}
});
} else {
res.sendStatus(500);
}
});
}
});
server.use(
APP_BASE,
connectLivereload({port: LIVE_RELOAD_PORT}),
express.static(process.cwd())
);
server.listen(PORT, () =>
openResource('http://localhost:' + PORT + APP_BASE + APP_DEST)
);
};