Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Refactor/typescript 4 #1696

Open
wants to merge 167 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
167 commits
Select commit Hold shift + click to select a range
3bd9808
add typescript
a60814billy Jun 11, 2021
45def87
temp comment pandoc (ts error)
a60814billy Jun 11, 2021
92c0575
ts: lib/homepage/index.ts
a60814billy Jun 11, 2021
bf1ca53
fix: type check error
a60814billy Jun 11, 2021
0387f67
let app can run use ts
a60814billy Jun 11, 2021
6469ac8
ts: lib/history/index.js
a60814billy Jun 11, 2021
758ffd4
ts: lib/middleware/checkURIValid.js
a60814billy Jun 11, 2021
68439de
ts: lib/middleware/codiMDVersion.js
a60814billy Jun 11, 2021
cf630ed
ts: lib/middleware/redirectWithoutTrailingSlashes.js
a60814billy Jun 11, 2021
231672d
ts: lib/middleware/tooBusy.js
a60814billy Jun 11, 2021
8ae51aa
ts: lib/imageRouter/azure.js
a60814billy Jun 11, 2021
8222f1f
ts: lib/imageRouter/filesystem.js
a60814billy Jun 11, 2021
e97c282
ts: lib/imageRouter/imgur.js
a60814billy Jun 11, 2021
307b6c5
allowSyntheticDefaultImports
a60814billy Jun 11, 2021
dbf1405
ts: lib/imageRouter/lutim.js
a60814billy Jun 11, 2021
5416baf
ts: lib/imageRouter/minio.ts
a60814billy Jun 11, 2021
4cfa5a1
ts: lib/imageRouter/s3.js
a60814billy Jun 11, 2021
87e2a25
ts: lib/imageRouter/s3.js
a60814billy Jun 11, 2021
710620a
ts: lib/imageRouter/minio.js
a60814billy Jun 11, 2021
352758c
ts: lib/imageRouter/lutim.js
a60814billy Jun 11, 2021
5b75f48
ts: lib/imageRouter/index.js
a60814billy Jun 11, 2021
3393c83
ts: lib/note/noteActions.js
a60814billy Jun 11, 2021
7827554
ts: lib/note/index.js
a60814billy Jun 11, 2021
fd5fe52
fix updateHistory argument typing
a60814billy Jun 11, 2021
d379bc7
ts: lib/errorPage/index.js
a60814billy Jun 11, 2021
52b4d13
ts: lib/realtime/processQueue.js
a60814billy Jun 11, 2021
0f8b126
ts: lib/realtime/realtimeCleanDanglingUserJob.js
a60814billy Jun 11, 2021
b38915d
ts: lib/realtime/realtimeSaveRevisionJob.js
a60814billy Jun 11, 2021
d7dc137
ts: lib/realtime/realtimeUpdateDirtyNoteJob.js
a60814billy Jun 11, 2021
d97fe35
ts: lib/realtime/realtimeClientConnection.js
a60814billy Jun 11, 2021
f21b234
ts: lib/realtime/processQueue.js
a60814billy Jun 11, 2021
16618e1
ts: lib/realtime/realtimeClientConneciton.js
a60814billy Jun 11, 2021
7cea9a2
ts: lib/realtime/realtime.ts
a60814billy Jun 11, 2021
efcaba9
ts: lib/status/index.js
a60814billy Jun 11, 2021
ced6f7f
ts: lib/user/index.js
a60814billy Jun 11, 2021
82ddb43
ts: lib/web/middleware/checkVersion.js
a60814billy Jun 11, 2021
e0322f0
ts: lib/worker/dmpWorker.js
a60814billy Jun 11, 2021
952a166
ts: lib/utils.js
a60814billy Jun 11, 2021
238bf1c
ts: lib/string.js
a60814billy Jun 11, 2021
e5e40d0
ts: lib/routes.js
a60814billy Jun 11, 2021
06a48e1
ts: lib/response.js
a60814billy Jun 11, 2021
b98e0c3
ts: lib/metrics.js
a60814billy Jun 11, 2021
7a6b2ef
ts: lib/letter-avatars.js
a60814billy Jun 11, 2021
8ea1eb2
ts: lib/csp.js
a60814billy Jun 11, 2021
385ef69
ts: lib/csp.js
a60814billy Jun 11, 2021
2a376db
ts: lib/logger.js
a60814billy Jun 11, 2021
294283f
ts: lib/config/utils.js
a60814billy Jun 11, 2021
8028e2c
ts: lib/config/utils.js
a60814billy Jun 11, 2021
b78cfc3
ts: lib/config/environment.js
a60814billy Jun 11, 2021
3b52b19
ts: lib/config/enum.js
a60814billy Jun 11, 2021
10e77f3
ts: lib/config/dockerSecret.js
a60814billy Jun 11, 2021
8d8d3f4
ts: lib/config/defaultSSL.js
a60814billy Jun 11, 2021
39c5636
ts: lib/config/default.js
a60814billy Jun 11, 2021
6696a0a
ts: lib/config/index.js
a60814billy Jun 11, 2021
5ba1a41
ts: lib/config/index.js
a60814billy Jun 11, 2021
b4f59ed
ts: lib/auth/utils.js
a60814billy Jun 11, 2021
d17c550
ts: lib/auth/bitbucket/index.js
a60814billy Jun 11, 2021
1ec3c0d
ts: lib/auth/dropbox/index.js
a60814billy Jun 11, 2021
89e0190
ts: lib/auth/email/index.js
a60814billy Jun 11, 2021
4c157d7
ts: lib/auth/facebook/index.js
a60814billy Jun 11, 2021
8309800
ts: lib/auth/github/index.js
a60814billy Jun 11, 2021
ce73196
ts: lib/auth/gitlab/index.js
a60814billy Jun 11, 2021
edc1a9d
ts: lib/auth/google/index.js
a60814billy Jun 11, 2021
6d920c0
ts: lib/auth/ldap/index.js
a60814billy Jun 11, 2021
0faebff
ts: lib/auth/mattermost/index.js
a60814billy Jun 11, 2021
b94c130
ts: lib/auth/twitter/index.js
a60814billy Jun 11, 2021
436a603
ts: lib/auth/saml/index.js
a60814billy Jun 11, 2021
8facb03
ts: lib/auth/openid/index.js
a60814billy Jun 11, 2021
ce5800b
ts: lib/auth/oauth2/strategy.js
a60814billy Jun 11, 2021
937b75d
ts: lib/auth/oauth2/index.js
a60814billy Jun 11, 2021
4b311b6
ts: lib/auth/auth/index.js
a60814billy Jun 11, 2021
147c200
ts: all migrations
a60814billy Jun 11, 2021
ebd8156
ts: lib/auth/facebook/index.js
a60814billy Jun 12, 2021
9a8d039
ts: lib/auth/twitter/index.js
a60814billy Jun 12, 2021
30c5197
ts: lib/auth/twitter/index.js
a60814billy Jun 12, 2021
a4c8a26
ts: lib/auth/mattermost/index.js
a60814billy Jun 12, 2021
1af9e91
ts: lib/auth/dropbox/index.js
a60814billy Jun 12, 2021
6a30382
change default sequelizerc
a60814billy Jun 12, 2021
79a427e
ts: lib/models/author.js
a60814billy Jun 12, 2021
492a7ac
ts: lib/models/user.js
a60814billy Jun 12, 2021
8d248ff
ts: lib/models/revision.js
a60814billy Jun 12, 2021
bc8ad1c
ts: lib/models/note.js
a60814billy Jun 12, 2021
8ba97c3
ts: lib/models/index.js
a60814billy Jun 12, 2021
b0b079a
migrate to use ot.js
a60814billy Jun 12, 2021
99e38d4
migrate to use ot.js - fix test
a60814billy Jun 12, 2021
e29eec0
ts: realtimeClientConnection.ts
a60814billy Jun 12, 2021
3017710
fix: realtime ts lint
a60814billy Jun 12, 2021
11fd1e7
fix minio ts error
a60814billy Jun 12, 2021
70ed184
ts to es2019
a60814billy Jun 12, 2021
da08b36
test case use dist build
a60814billy Jun 12, 2021
725ba14
enable noImplicitReturns
a60814billy Jun 12, 2021
4d2579f
add lint
a60814billy Jun 12, 2021
48b7837
fix: incorrect logic
a60814billy Jun 12, 2021
5128815
fix all eslint error
a60814billy Jun 12, 2021
a10263b
upgrade sequelize
a60814billy Jun 12, 2021
74f9e57
ot server patch
a60814billy Jun 12, 2021
f04e632
limit model should be .js files
a60814billy Jun 12, 2021
6f93e43
move app.js to lib/
a60814billy Jun 12, 2021
67491af
fix: public path
a60814billy Jun 12, 2021
0191964
use new parameter in hsts
a60814billy Jun 12, 2021
72ca90a
upgrade winston
a60814billy Jun 12, 2021
6d512c0
adjust logger
a60814billy Jun 12, 2021
8fb31bd
upgrade morgan to 1.10
a60814billy Jun 12, 2021
41f0e61
use winston.http to log morgan, and adjust development output
a60814billy Jun 12, 2021
f73e72b
fix: i18n path
a60814billy Jun 12, 2021
aaf019e
enable esModuleInterop
a60814billy Jun 12, 2021
d1a440e
refactor logger export
a60814billy Jun 12, 2021
db55d00
refactor: use config insted of * as config
a60814billy Jun 12, 2021
638a887
refactor: use strong type in models
a60814billy Jun 13, 2021
ff90fd0
test: fix test case
a60814billy Jun 12, 2021
6e8ff98
remove * as models
a60814billy Jun 12, 2021
cb1f263
format
a60814billy Jun 12, 2021
05cd6dd
fix: heroku
a60814billy Jun 12, 2021
3494922
fix: docker
a60814billy Jun 12, 2021
375de57
fix: guest note not save
a60814billy Jun 12, 2021
adc0a62
lint: lib/auth/email/index.ts
a60814billy Jun 13, 2021
8f0337a
lint: lib/auth/ldap.index.ts
a60814billy Jun 13, 2021
08fb685
lint: lib/auth/openid/index.ts
a60814billy Jun 13, 2021
a965ba8
lint: lib/auth/saml/index.ts
a60814billy Jun 13, 2021
dded39c
lint: lib/string.ts
a60814billy Jun 13, 2021
5a7c38c
lint: lib/letter-avatars.ts
a60814billy Jun 13, 2021
ba8b1f1
lint: lib/response.ts
a60814billy Jun 13, 2021
7429d5e
lint: lib/status/index.ts
a60814billy Jun 13, 2021
90ab2d0
lint: lib/csp.ts
a60814billy Jun 13, 2021
f08097f
lint: lib/middleware
a60814billy Jun 13, 2021
eaf54c4
lint: lib/imageRouter
a60814billy Jun 13, 2021
6d70f79
lib/homepage/index.ts
a60814billy Jun 13, 2021
738a4b4
lint: lib/history/index.ts
a60814billy Jun 13, 2021
016e169
lint: lib/services/note.ts
a60814billy Jun 13, 2021
a5376a4
lint: lib/auth/utils.ts
a60814billy Jun 13, 2021
bc41704
lint: lib/utils.ts
a60814billy Jun 13, 2021
d6c9c66
refactor: lib/models
a60814billy Jun 13, 2021
c7f712d
lint: lib/auth/oauth2/strategy.ts
a60814billy Jun 13, 2021
d19908d
lint lib/auth/index.ts
a60814billy Jun 13, 2021
e6b9ab0
lint lib/config
a60814billy Jun 13, 2021
7dbb1ef
lint: lib/models
a60814billy Jun 13, 2021
10e5cd8
lint: lib/realtime
a60814billy Jun 13, 2021
ee04b2f
lint: lib/note/noteAction.ts
a60814billy Jun 13, 2021
534492e
lint: lib/note/index.ts
a60814billy Jun 13, 2021
0427b1b
web/middleware/checkVersion.ts
a60814billy Jun 13, 2021
fc2658b
lint: lib/utils.ts
a60814billy Jun 13, 2021
2944da0
lint: lib/realtime/realtime.ts
a60814billy Jun 13, 2021
7e963e7
lint: lib/user/index.ts
a60814billy Jun 13, 2021
a095cd3
lint: lib/realtime/realtimeClientConnection
a60814billy Jun 13, 2021
ab2ed4a
realtime RealtimeUserData
a60814billy Jun 13, 2021
dee7bf2
realtimeClientConnection.ts add RealtimeUserData type
a60814billy Jun 13, 2021
13e64b0
lint: lib/realtime/realtime
a60814billy Jun 13, 2021
6d04d60
add .eslintignore file
a60814billy Jun 13, 2021
075a8f9
lib/auth/oauth2/strategy.ts
a60814billy Jun 13, 2021
9ef827f
lint: lib/note/noteActions.ts
a60814billy Jun 13, 2021
3eca238
lint: lib/workers/dmpWorker.ts
a60814billy Jun 14, 2021
c7b0362
lint: lib/models/note.ts
a60814billy Jun 14, 2021
73e322f
lint: lib/models/note.ts
a60814billy Jun 14, 2021
97b6c1e
fix: cursor data and user status
a60814billy Jun 14, 2021
1f26f6a
fix: process queue default value not accept
a60814billy Jun 14, 2021
3bfbcb2
refactor: simplefy processQueue.ts
a60814billy Jun 14, 2021
3c370fe
chore: add strictBindCallApply, preserveConstEnums, noImplicitThis, s…
a60814billy Jun 14, 2021
d656d63
lint: lib/realtime
a60814billy Jun 14, 2021
847acda
lint: lib/realtime/realtime.ts
a60814billy Jun 14, 2021
f35d684
lint: lib/realtime/realtime.ts
a60814billy Jun 14, 2021
d2eed82
upgrade to webpack 5
a60814billy Jul 30, 2021
4dfb6e9
upgrade expose-loader to 2.0.0
a60814billy Jul 31, 2021
e0835bb
upgrade babel to 7
a60814billy Jul 31, 2021
ed80cb2
remove unused webpack plugins
a60814billy Jul 31, 2021
2135fb0
convert frontend to ts
a60814billy Jul 31, 2021
e4855cd
move all files to .ts
a60814billy Jul 31, 2021
f83b4b7
refactor
a60814billy Jul 31, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"presets": [
["env", {
["@babel/preset-env", {
"useBuiltIns": "entry",
"corejs": 2,
"targets": {
"node": "6",
"uglify": true
}
}]
}],
"@babel/preset-typescript"
],
"plugins": [
"transform-runtime"
"@babel/plugin-transform-runtime"
]
}
7 changes: 7 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/dist
/public
node_modules
/test
/*.js

lib/migrations
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ public/uploads/*
/.nyc_output
/coverage/

.vscode/settings.json
.vscode/settings.json

/dist
lib/**/*.js
6 changes: 3 additions & 3 deletions .sequelizerc.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const path = require('path')
const config = require('./lib/config')
const config = require('./dist/config')

module.exports = {
config: path.resolve('config.js'),
'migrations-path': path.resolve('lib', 'migrations'),
'models-path': path.resolve('lib', 'models'),
'migrations-path': path.resolve('dist', 'migrations'),
'models-path': path.resolve('dist', 'models'),
url: config.dbURL
}
330 changes: 1 addition & 329 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,331 +1,3 @@
'use strict'
// app
// external modules
var express = require('express')

var ejs = require('ejs')
var passport = require('passport')
var methodOverride = require('method-override')
var cookieParser = require('cookie-parser')
var session = require('express-session')
var SequelizeStore = require('connect-session-sequelize')(session.Store)
var fs = require('fs')
var path = require('path')

var morgan = require('morgan')
var passportSocketIo = require('passport.socketio')
var helmet = require('helmet')
var i18n = require('i18n')
var flash = require('connect-flash')
var apiMetrics = require('prometheus-api-metrics')

// core
var config = require('./lib/config')
var logger = require('./lib/logger')
var response = require('./lib/response')
var models = require('./lib/models')
var csp = require('./lib/csp')
const { Environment } = require('./lib/config/enum')

const { versionCheckMiddleware, checkVersion } = require('./lib/web/middleware/checkVersion')

function createHttpServer () {
if (config.useSSL) {
const ca = (function () {
let i, len
const results = []
for (i = 0, len = config.sslCAPath.length; i < len; i++) {
results.push(fs.readFileSync(config.sslCAPath[i], 'utf8'))
}
return results
})()
const options = {
key: fs.readFileSync(config.sslKeyPath, 'utf8'),
cert: fs.readFileSync(config.sslCertPath, 'utf8'),
ca: ca,
dhparam: fs.readFileSync(config.dhParamPath, 'utf8'),
requestCert: false,
rejectUnauthorized: false
}
return require('https').createServer(options, app)
} else {
return require('http').createServer(app)
}
}

// server setup
var app = express()
var server = createHttpServer()

// API and process monitoring with Prometheus for Node.js micro-service
app.use(apiMetrics({
metricsPath: '/metrics/router',
excludeRoutes: ['/metrics/codimd']
}))

// logger
app.use(morgan('combined', {
stream: logger.stream
}))

// socket io
var io = require('socket.io')(server)
io.engine.ws = new (require('ws').Server)({
noServer: true,
perMessageDeflate: false
})

// others
var realtime = require('./lib/realtime/realtime.js')

// assign socket io to realtime
realtime.io = io

// methodOverride
app.use(methodOverride('_method'))

// session store
var sessionStore = new SequelizeStore({
db: models.sequelize
})

// use hsts to tell https users stick to this
if (config.hsts.enable) {
app.use(helmet.hsts({
maxAge: config.hsts.maxAgeSeconds,
includeSubdomains: config.hsts.includeSubdomains,
preload: config.hsts.preload
}))
} else if (config.useSSL) {
logger.info('Consider enabling HSTS for extra security:')
logger.info('https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security')
}

// Add referrer policy to improve privacy
app.use(
helmet.referrerPolicy({
policy: 'same-origin'
})
)

// Generate a random nonce per request, for CSP with inline scripts
app.use(csp.addNonceToLocals)

// use Content-Security-Policy to limit XSS, dangerous plugins, etc.
// https://helmetjs.github.io/docs/csp/
if (config.csp.enable) {
app.use(helmet.contentSecurityPolicy({
directives: csp.computeDirectives()
}))
} else {
logger.info('Content-Security-Policy is disabled. This may be a security risk.')
}

i18n.configure({
locales: ['en', 'zh-CN', 'zh-TW', 'fr', 'de', 'ja', 'es', 'ca', 'el', 'pt', 'it', 'tr', 'ru', 'nl', 'hr', 'pl', 'uk', 'hi', 'sv', 'eo', 'da', 'ko', 'id', 'sr'],
cookie: 'locale',
directory: path.join(__dirname, '/locales'),
updateFiles: config.updateI18nFiles
})

app.use(cookieParser())

app.use(i18n.init)

// routes without sessions
// static files
app.use('/', express.static(path.join(__dirname, '/public'), { maxAge: config.staticCacheTime, index: false }))
app.use('/docs', express.static(path.resolve(__dirname, config.docsPath), { maxAge: config.staticCacheTime }))
app.use('/uploads', express.static(path.resolve(__dirname, config.uploadsPath), { maxAge: config.staticCacheTime }))
app.use('/default.md', express.static(path.resolve(__dirname, config.defaultNotePath), { maxAge: config.staticCacheTime }))
app.use(require('./lib/metrics').router)

// session
app.use(session({
name: config.sessionName,
secret: config.sessionSecret,
resave: false, // don't save session if unmodified
saveUninitialized: true, // always create session to ensure the origin
rolling: true, // reset maxAge on every response
cookie: {
maxAge: config.sessionLife
},
store: sessionStore
}))

// session resumption
var tlsSessionStore = {}
server.on('newSession', function (id, data, cb) {
tlsSessionStore[id.toString('hex')] = data
cb()
})
server.on('resumeSession', function (id, cb) {
cb(null, tlsSessionStore[id.toString('hex')] || null)
})

// middleware which blocks requests when we're too busy
app.use(require('./lib/middleware/tooBusy'))

app.use(flash())

// passport
app.use(passport.initialize())
app.use(passport.session())

// check uri is valid before going further
app.use(require('./lib/middleware/checkURIValid'))
// redirect url without trailing slashes
app.use(require('./lib/middleware/redirectWithoutTrailingSlashes'))
app.use(require('./lib/middleware/codiMDVersion'))

if (config.autoVersionCheck && process.env.NODE_ENV === Environment.production) {
checkVersion(app)
app.use(versionCheckMiddleware)
}

// routes need sessions
// template files
app.set('views', config.viewPath)
// set render engine
app.engine('ejs', ejs.renderFile)
// set view engine
app.set('view engine', 'ejs')
// set generally available variables for all views
app.locals.useCDN = config.useCDN
app.locals.serverURL = config.serverURL
app.locals.sourceURL = config.sourceURL
app.locals.privacyPolicyURL = config.privacyPolicyURL
app.locals.allowAnonymous = config.allowAnonymous
app.locals.allowAnonymousEdits = config.allowAnonymousEdits
app.locals.permission = config.permission
app.locals.allowPDFExport = config.allowPDFExport
app.locals.authProviders = {
facebook: config.isFacebookEnable,
twitter: config.isTwitterEnable,
github: config.isGitHubEnable,
bitbucket: config.isBitbucketEnable,
gitlab: config.isGitLabEnable,
mattermost: config.isMattermostEnable,
dropbox: config.isDropboxEnable,
google: config.isGoogleEnable,
ldap: config.isLDAPEnable,
ldapProviderName: config.ldap.providerName,
saml: config.isSAMLEnable,
oauth2: config.isOAuth2Enable,
oauth2ProviderName: config.oauth2.providerName,
openID: config.isOpenIDEnable,
email: config.isEmailEnable,
allowEmailRegister: config.allowEmailRegister
}
app.locals.versionInfo = {
latest: true,
versionItem: null
}

// Export/Import menu items
app.locals.enableDropBoxSave = config.isDropboxEnable
app.locals.enableGitHubGist = config.isGitHubEnable
app.locals.enableGitlabSnippets = config.isGitlabSnippetsEnable

app.use(require('./lib/routes').router)

// response not found if no any route matxches
app.get('*', function (req, res) {
response.errorNotFound(req, res)
})

// socket.io secure
io.use(realtime.secure)
// socket.io auth
io.use(passportSocketIo.authorize({
cookieParser: cookieParser,
key: config.sessionName,
secret: config.sessionSecret,
store: sessionStore,
success: realtime.onAuthorizeSuccess,
fail: realtime.onAuthorizeFail
}))
// socket.io heartbeat
io.set('heartbeat interval', config.heartbeatInterval)
io.set('heartbeat timeout', config.heartbeatTimeout)
// socket.io connection
io.sockets.on('connection', realtime.connection)

// listen
function startListen () {
var address
var listenCallback = function () {
var schema = config.useSSL ? 'HTTPS' : 'HTTP'
logger.info('%s Server listening at %s', schema, address)
realtime.maintenance = false
}

// use unix domain socket if 'path' is specified
if (config.path) {
address = config.path
server.listen(config.path, listenCallback)
} else {
address = config.host + ':' + config.port
server.listen(config.port, config.host, listenCallback)
}
}

// sync db then start listen
models.sequelize.sync().then(function () {
// check if realtime is ready
if (realtime.isReady()) {
models.Revision.checkAllNotesRevision(function (err, notes) {
if (err) throw new Error(err)
if (!notes || notes.length <= 0) return startListen()
})
} else {
throw new Error('server still not ready after db synced')
}
}).catch(err => {
logger.error('Can\'t sync database')
logger.error(err.stack)
logger.error('Process will exit now.')
process.exit(1)
})

// log uncaught exception
process.on('uncaughtException', function (err) {
logger.error('An uncaught exception has occured.')
logger.error(err)
console.error(err)
logger.error('Process will exit now.')
process.exit(1)
})

// install exit handler
function handleTermSignals () {
logger.info('CodiMD has been killed by signal, try to exit gracefully...')
realtime.maintenance = true
realtime.terminate()
// disconnect all socket.io clients
Object.keys(io.sockets.sockets).forEach(function (key) {
var socket = io.sockets.sockets[key]
// notify client server going into maintenance status
socket.emit('maintenance')
setTimeout(function () {
socket.disconnect(true)
}, 0)
})
var checkCleanTimer = setInterval(function () {
if (realtime.isReady()) {
models.Revision.checkAllNotesRevision(function (err, notes) {
if (err) return logger.error(err)
if (!notes || notes.length <= 0) {
clearInterval(checkCleanTimer)
return process.exit(0)
}
})
}
}, 100)
setTimeout(() => {
process.exit(1)
}, 5000)
}
process.on('SIGINT', handleTermSignals)
process.on('SIGTERM', handleTermSignals)
process.on('SIGQUIT', handleTermSignals)
require('./dist/app.js')
Loading