-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathnodeico.js
More file actions
39 lines (32 loc) · 876 Bytes
/
nodeico.js
File metadata and controls
39 lines (32 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import fs from 'fs'
import bole from 'bole'
import createServer from './nodeico-fastify.js'
// Setup logging
const isDev = (/^dev/i).test(process.env.NODE_ENV)
bole.output({
level: isDev ? 'debug' : 'info',
stream: process.stdout
})
if (process.env.LOG_FILE) {
console.log(`Starting logging to ${process.env.LOG_FILE}`)
bole.output({
level: 'debug',
stream: fs.createWriteStream(process.env.LOG_FILE)
})
}
const log = bole('server')
const port = process.env.PORT || 3000
const host = process.env.HOST || 'localhost'
if (import.meta.url === `file://${process.argv[1]}`) {
const server = createServer()
server.listen({ port, host }, (err) => {
if (err) {
log.error(err)
throw err
}
log.info(`Server started on ${host}:${port}`)
console.log()
console.log(`>> Running: http://${host}:${port}`)
console.log()
})
}