Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const root = './dist'
const port = process.env.PORT || argv['port'] || 8001
const host = process.env.HOST || argv['host'] || 'http://localhost'
const isProd = argv['build-type'] === 'prod' || argv['prod']
const isTest = argv['e2e']
const staticOptions = {
index: false,
maxAge: isProd ? ms('1yr') : ms('0'),
setHeaders: (res: express.Response, path: any) => {
res.setHeader('Expires', isProd
? new Date(Date.now() + ms('1yr')).toUTCString()
: new Date(Date.now() + ms('0')).toUTCString())
}
}
const logger = createLogger({
name: 'Angular Universal App',
type: 'http',
streams: [{
level: 'error',
stream: { write: (err: any) => console.log },
type: 'raw'
}] as any
})
if (!isTest) app.use(bunyanMiddleware({ logger, excludeHeaders: ['authorization', 'cookie'] }))
useWebSockets(server) // uncomment to activate manual web-sockets
app.engine('html', ngExpressEngine({ bootstrap: AppServerModule }))
app.set('view engine', 'html')
app.set('views', root)
app.use(cookieParser())
class ConsoleRawStream {
write(rec) {
if (rec.level < bunyan.INFO) {
console.log(rec);
} else if (rec.level < bunyan.WARN) {
console.info(rec);
} else if (rec.level < bunyan.ERROR) {
console.warn(rec);
} else {
console.error(rec);
}
}
}
// TODO(perry) teach flow about the logger type here
let logger: any = bunyan.createLogger({
name: 'expo',
serializers: bunyan.stdSerializers,
streams: [
{
level: 'debug',
type: 'rotating-file',
path: path.join(UserSettings.dotExpoHomeDirectory(), 'log'),
period: '1d', // daily rotation
count: 3, // keep 3 back copies
},
...(process.env.DEBUG && process.env.NODE_ENV !== 'production'
? [
{
type: 'raw',
stream: new ConsoleRawStream(),
closeOnExit: false,
const isProd = config.server.prodMode
const port = config.server.port
const host = config.server.host
const staticOptions = {
index: false,
maxAge: isProd ? ms('1yr') : ms('0'),
setHeaders: (res: express.Response, path: any) => {
res.setHeader('Expires', isProd ? ms('1yr').toString() : ms('0').toString())
}
}
// setup logger
if (config.env === 'dev') {
app.use(morgan('dev'))
} else {
const logger = createLogger({ name: 'Angular Universal App', type: 'http-access' })
app.use(bunyanMiddleware({ logger, excludeHeaders: ['authorization', 'cookie'] }))
}
if (process.env.HEROKU) app.use(forceSsl)
app.engine('html', ngExpressEngine({ bootstrap: AppServerModule }))
app.set('view engine', 'html')
app.set('views', root)
app.use(cookieParser())
app.use(shrinkRay())
if (config.server.minifyIndex) {
app.use(minifyHTML({
override: true,
exception_url: false,
htmlMinifier: {
removeComments: true,
class ConsoleRawStream {
write(record: any) {
if (record.level < bunyan.INFO) {
console.log(record);
} else if (record.level < bunyan.WARN) {
console.info(record);
} else if (record.level < bunyan.ERROR) {
console.warn(record);
} else {
console.error(record);
}
}
}
const logger = bunyan.createLogger({
name: 'expo',
serializers: bunyan.stdSerializers,
streams:
process.env.DEBUG && process.env.NODE_ENV !== 'production'
? [
{
type: 'raw',
stream: new ConsoleRawStream(),
closeOnExit: false,
level: 'debug',
},
]
: [],
});
export type LogStream = bunyan.Stream;
init(levels) {
this.loggerObj = PRINT_JSON_LOGS ? bunyan.createLogger({ name: LOGGER_NAME }) : console;
this.configured = PRINT_JSON_LOGS;
this.selfConfigured = this.configured && true;
this.extraFields = {};
levels.forEach(level => {
this[level] = function(...args) {
this.logLine(level, ...args);
};
});
},
configure(loggerObj) {
constructor(bunyanGetter?: BunyanGetter, extraFields?: any) {
this.loggerObj = bunyan.createLogger({ name: 'xdl-detach' });
this.loggerGetter = bunyanGetter;
this.extraFields = extraFields;
}
msg: string,
errObj?: { readonly [key: string]: any },
extendedObj?: { readonly [key: string]: any }
): void
error(
msg: string,
errObj?: { readonly [key: string]: any },
extendedObj?: { readonly [key: string]: any }
): void
}
export const LOGGER_CONFIG = new InjectionToken('cfg.logger')
@Injectable()
export class LoggingService implements ILoggingService {
private readonly logger = createLogger(this.loggerConfig)
constructor(@Inject(LOGGER_CONFIG) private loggerConfig: LoggerOptions) {}
trace(
msg: string,
obj: { readonly [key: string]: any } = {},
extendedObj: { readonly [key: string]: any } = {}
): void {
this.logger.trace({ trace: { msg, ...obj }, ...extendedObj }, msg)
}
debug(
msg: string,
obj: { readonly [key: string]: any } = {},
extendedObj: { readonly [key: string]: any } = {}
): void {
index: false,
maxAge: isProd ? ms('1y') : ms('0'),
setHeaders: (res: express.Response, path: any) => {
res.setHeader(
'Expires',
isProd
? new Date(Date.now() + ms('1y')).toUTCString()
: new Date(Date.now() + ms('0')).toUTCString()
)
}
}
!isEndToEndTest &&
app.use(
bunyanMiddleware({
logger: createLogger({
name: 'Fusing-Angular',
type: 'node-express'
}),
excludeHeaders: ['authorization', 'cookie']
})
)
const dir = resolve('dist')
app.engine('html', ngExpressEngine({ bootstrap: AppServerModule }))
app.set('ignore-routes', ['/api/'])
app.set('view engine', 'html')
app.set('views', dir)
app.use(cookieParser())
app.use(shrinkRay())
app.use(cors())
import { Inject, Injectable, InjectionToken } from '@angular/core'
import { createLogger, LoggerOptions } from '@expo/bunyan'
export interface ILoggingService {
trace(msg: string, errObj?: { readonly [key: string]: any }, extendedObj?: { readonly [key: string]: any }): void
debug(msg: string, errObj?: { readonly [key: string]: any }, extendedObj?: { readonly [key: string]: any }): void
info(msg: string, errObj?: { readonly [key: string]: any }, extendedObj?: { readonly [key: string]: any }): void
warn(msg: string, errObj?: { readonly [key: string]: any }, extendedObj?: { readonly [key: string]: any }): void
error(msg: string, errObj?: { readonly [key: string]: any }, extendedObj?: { readonly [key: string]: any }): void
}
export const LOGGER_CONFIG = new InjectionToken('app.logger.config')
@Injectable()
export class LoggingService implements ILoggingService {
private readonly logger = createLogger(this.loggerConfig)
constructor(@Inject(LOGGER_CONFIG) private loggerConfig: LoggerOptions) { }
trace(msg: string, obj: { readonly [key: string]: any } = {}, extendedObj: { readonly [key: string]: any } = {}): void {
this.logger.trace({ trace: { msg, ...obj }, ...extendedObj }, msg)
}
debug(msg: string, obj: { readonly [key: string]: any } = {}, extendedObj: { readonly [key: string]: any } = {}): void {
this.logger.debug({ debug: { msg, ...obj }, ...extendedObj }, msg)
}
info(msg: string, obj: { readonly [key: string]: any } = {}, extendedObj: { readonly [key: string]: any } = {}): void {
this.logger.info({ info: { msg, ...obj }, ...extendedObj }, msg)
}
warn(msg: string, obj: { readonly [key: string]: any } = {}, extendedObj: { readonly [key: string]: any } = {}): void {