本文整理匯總了TypeScript中ip.address函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript address函數的具體用法?TypeScript address怎麽用?TypeScript address使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了address函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
server.start((err: any) => {
if (err) {
throw err;
} else {
console.log(`Server running at: http://${Ip.address()}:${server.info.port}`);
}
});
示例2: log
export async function log(log: LogInterface): Promise<boolean> {
if (!log.userId) {
log.userId = null;
}
if (!log.module) {
log.module = '';
}
log.module = log.module.toLowerCase();
if (!log.type) {
log.type = '';
}
const newLog = new MoLogs();
newLog.module = log.module;
newLog.type = log.type;
newLog.date = new Date();
newLog.ip = address();
newLog.info = log.info;
newLog.userId = log.userId;
await getConnection().getRepository(MoLogs).save(newLog);
return true;
}
示例3: checkBruteForce
private async checkBruteForce(): Promise<boolean> {
// Remove timed out IPs
this.timeOutAuthAttempts(true);
try {
// Fetching previous attempts to login
const response = await getConnection().getRepository(MoUsersAuthAttempts)
.findOne({
ip: address()
});
if (response && response.attempts >= this.availableLoginAttempts) {
// Immediately trigger response as false to block off bruteforce
return false;
}
if (response) {
// In case there were already attempts, we're incrementing the attempt
response.attempts++;
await getConnection().getRepository(MoUsersAuthAttempts).save(response);
} else {
// Saving first attempt from this IP address
const usersAuthAttempts: MoUsersAuthAttempts = new MoUsersAuthAttempts();
usersAuthAttempts.attempts = 1;
usersAuthAttempts.timestamp = new Date();
usersAuthAttempts.ip = address();
await getConnection().getRepository(MoUsersAuthAttempts).save(usersAuthAttempts);
}
return true;
} catch (error) {
return false;
}
return true;
}
示例4: appStarted
// Called when express.js app starts on given port w/o errors
public static appStarted(port: number, tunnelStarted?: string) {
console.log(`Server started ${chalk.green('â')}`);
// If the tunnel started, log that and the URL it's available at
if (tunnelStarted) {
console.log(`Tunnel initialised ${chalk.green('â')}`);
}
console.log(`
${chalk.bold('Access URLs:')}${divider}
Localhost: ${chalk.magenta(`http://localhost:${port}`)}
LAN: ${chalk.magenta(`http://${ip.address()}:${port}`) +
(tunnelStarted ? `\n Proxy: ${chalk.magenta(tunnelStarted)}` : '')}${divider}
${chalk.blue(`Press ${chalk.italic('CTRL-C')} to stop`)}
`);
}
示例5: timeOutAuthAttempts
private async timeOutAuthAttempts(timer: boolean = false): Promise<boolean> {
const findByRules = {
ip: address(),
timestamp: null
};
// Just in case if we need to check by timestamp
if (timer) {
findByRules.timestamp = LessThan(format(subMinutes(new Date(), 5), 'YYYY-MM-DD HH:mm:ss'));
}
// Fetching attempts
const response = await getConnection().getRepository(MoUsersAuthAttempts).find(findByRules);
// Cleaning up outdated attempts
if (response) {
await getConnection().getRepository(MoUsersAuthAttempts).remove(response);
}
return true;
}
示例6: startServerProcess
import child_process from 'child_process';
import chokidar from 'chokidar';
import ip from 'ip';
import path from 'path';
const address = ip.address();
let timeout;
let serverProcess: child_process.ChildProcess;
// start building
const buildProcess = child_process.spawn('npm', ['run', 'build'], {
env: {
...process.env,
LOCAL_IP: address,
},
stdio: [0, 1, 2],
});
startServerProcess();
// watch file change and restart server
const watcher = chokidar
.watch([path.resolve(__dirname, './'), path.resolve(__dirname, '../web/common')])
.on('add', startServerProcess)
.on('change', startServerProcess)
.on('unlink', startServerProcess);
function startServerProcess(f?: string) {
clearTimeout(timeout);
timeout = setTimeout(() => {
if (f) {
console.info(f + ' changed, restart server...');
示例7:
import * as Ip from 'ip';
import { Config } from './../share/config';
const host: string = `${Ip.address()}:${Config.PORT}`;
process.once('loaded', () => {
global['appHost'] = host;
});
示例8: EventEmitter
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {EventEmitter} from 'events';
import ip from 'ip';
import {ITrace} from './types';
const pid = process.pid;
const ipAddr = ip.address();
export const msg = new EventEmitter();
export const isDevEnv = process.env.NODE_ENV !== 'production';
/**
* yes, just do nothing.
*/
export const noop = () => {};
/**
* trace log
* @param info
*/
export const trace = (obj: ITrace) => {