Timers and other features for Heroes of the Storm
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

111 satır
3.2 KiB

  1. /*
  2. * Copyright © 2021 Adrien Agez <adrien.agez@pm.me>
  3. *
  4. * This file is part of Nexus Timers.
  5. *
  6. * Nexus Timers is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Nexus Timers is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with Nexus Timers. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. 'use strict'
  20. require('./check-versions')()
  21. const config = require('../config')
  22. if (!process.env.NODE_ENV) {
  23. process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
  24. }
  25. const opn = require('opn')
  26. const path = require('path')
  27. const express = require('express')
  28. const webpack = require('webpack')
  29. const proxyMiddleware = require('http-proxy-middleware')
  30. const webpackConfig = require('./webpack.dev.conf')
  31. // default port where dev server listens for incoming traffic
  32. const port = process.env.PORT || config.dev.port
  33. // automatically open browser, if not set will be false
  34. const autoOpenBrowser = !!config.dev.autoOpenBrowser
  35. // Define HTTP proxies to your custom API backend
  36. // https://github.com/chimurai/http-proxy-middleware
  37. const proxyTable = config.dev.proxyTable
  38. const app = express()
  39. const compiler = webpack(webpackConfig)
  40. const devMiddleware = require('webpack-dev-middleware')(compiler, {
  41. publicPath: webpackConfig.output.publicPath,
  42. quiet: true
  43. })
  44. const hotMiddleware = require('webpack-hot-middleware')(compiler, {
  45. log: false
  46. })
  47. // force page reload when html-webpack-plugin template changes
  48. compiler.plugin('compilation', function (compilation) {
  49. compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
  50. hotMiddleware.publish({ action: 'reload' })
  51. cb()
  52. })
  53. })
  54. // enable hot-reload and state-preserving
  55. // compilation error display
  56. app.use(hotMiddleware)
  57. // proxy api requests
  58. Object.keys(proxyTable).forEach(function (context) {
  59. let options = proxyTable[context]
  60. if (typeof options === 'string') {
  61. options = { target: options }
  62. }
  63. app.use(proxyMiddleware(options.filter || context, options))
  64. })
  65. // handle fallback for HTML5 history API
  66. app.use(require('connect-history-api-fallback')())
  67. // serve webpack bundle output
  68. app.use(devMiddleware)
  69. // serve pure static assets
  70. const staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
  71. app.use(staticPath, express.static('./static'))
  72. const uri = 'http://localhost:' + port
  73. let _resolve
  74. const readyPromise = new Promise(resolve => {
  75. _resolve = resolve
  76. })
  77. console.log('> Starting dev server...')
  78. devMiddleware.waitUntilValid(() => {
  79. console.log('> Listening at ' + uri + '\n')
  80. // when env is testing, don't need open it
  81. if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
  82. opn(uri)
  83. }
  84. _resolve()
  85. })
  86. const server = app.listen(port)
  87. module.exports = {
  88. ready: readyPromise,
  89. close: () => {
  90. server.close()
  91. }
  92. }