diff --git a/assets/App.vue b/assets/App.vue index 9190a57..8ec4a9a 100644 --- a/assets/App.vue +++ b/assets/App.vue @@ -3,7 +3,6 @@ @@ -35,7 +34,7 @@ class="ripple" ripple :to="subItem.href" - key="subItem.title"> + :key="subItem.title"> {{ subItem.action }} @@ -45,7 +44,7 @@ - {{ item.header }} + {{ item.header }} diff --git a/dist/.gitkeep b/dist/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/main.js b/main.js index d76d857..e338a2f 100644 --- a/main.js +++ b/main.js @@ -7,7 +7,7 @@ const express = require('express') const compression = require('compression') const resolve = file => path.resolve(__dirname, file) const { createBundleRenderer } = require('vue-server-renderer') -const redirects = require('./router/301.json') +const redirects = require(path.join(__dirname, '/router/301.json')) const isDev = process.env.NODE_ENV === 'development' const useMicroCache = process.env.MICRO_CACHE !== 'false' @@ -17,7 +17,7 @@ const serverInfo = const app = express() -const template = fs.readFileSync(resolve('./assets/index.template.html'), 'utf-8') +const template = fs.readFileSync(path.join(__dirname, 'assets/index.template.html'), 'utf-8') function createRenderer (bundle, options) { // https://github.com/vuejs/vue/blob/dev/packages/vue-server-renderer/README.md#why-use-bundlerenderer @@ -29,7 +29,7 @@ function createRenderer (bundle, options) { maxAge: 1000 * 60 * 15 }), // this is only needed when vue-server-renderer is npm-linked - basedir: resolve('./public'), + basedir: resolve(__dirname, 'public'), // performance runInNewContext: false })) @@ -38,14 +38,14 @@ function createRenderer (bundle, options) { let renderer let readyPromise if (!isDev) { - const bundle = require('./public/vue-ssr-server-bundle.json') - const clientManifest = require('./public/vue-ssr-client-manifest.json') + const bundle = require(path.join(__dirname, 'public', 'vue-ssr-server-bundle.json')) + const clientManifest = require(path.join(__dirname, 'public', 'vue-ssr-client-manifest.json')) renderer = createRenderer(bundle, { clientManifest }) } else { // hot reload - readyPromise = require('./webpack/setup-dev-server')(app, (bundle, options) => { + readyPromise = require(path.join(__dirname, 'webpack', 'setup-dev-server.js'))(app, (bundle, options) => { renderer = createRenderer(bundle, options) }) } @@ -55,17 +55,11 @@ const serve = (path, cache) => express.static(resolve(path), { }) app.use(compression({ threshold: 0 })) -app.use('/static', serve('./static', true)) -app.use('/public', serve('./public', true)) -app.use('/static/robots.txt', serve('./robots.txt')) - -app.get('/sitemap.xml', (req, res) => { - res.setHeader('Content-Type', 'text/xml') - res.sendFile(resolve('./static/sitemap.xml')) -}) +app.use('/static', serve(path.join(__dirname, 'static'), true)) +app.use('/public', serve(path.join(__dirname, 'public'), true)) // Setup the api -require('./server')(app) +require(path.join(__dirname, 'server'))(app) // 301 redirect for changed routes Object.keys(redirects).forEach((k) => { @@ -92,7 +86,7 @@ function render ({url}, res) { res.status(404).end('404 | Page Not Found') } else { // Render Error Page or Redirect - res.status(500).end('500 | Internal Server Error') + res.status(500).end('500 | Internal Server Error\n' + err.stack) console.error(`error during render : ${url}`) console.error(err.stack) } @@ -129,11 +123,9 @@ app.get('*', !isDev ? render : (req, res) => { }) }) -const port = process.env.PORT || 9200 -const _APP_URL_ = `http://localhost:${port}` -app.listen(port, '0.0.0.0', () => { - console.log(`> server started at localhost:${port}`.green) -}) +const server = http.createServer(app).listen() +const _APP_URL_ = 'http://localhost:' + server.address().port +console.log(`> server started at ${_APP_URL_}`.green) /* ** Electron app @@ -162,7 +154,7 @@ dialog.showErrorBox = (title, content) => { } process.on('uncaughtException', (err) => { - console.error('Uncaught exception occurred in main process.\n' + err.message) + console.error('Uncaught exception occurred in main process.\n', err) }) const newWin = () => { @@ -223,6 +215,7 @@ Electron.on('window-all-closed', function () { // to stay active until the user quits explicitly with Cmd + Q if (process.platform !== 'darwin') { app.quit() + Electron.quit() } }) diff --git a/nightwatch.conf.js b/nightwatch.conf.js index 68e465c..97c2fca 100644 --- a/nightwatch.conf.js +++ b/nightwatch.conf.js @@ -2,7 +2,6 @@ * Taken and modified from https://github.com/dwyl/learn-nightwatch */ // require('env2')('.env') // optionally store your Evironment Variables in .env -process.NODE_ENV = 'KawAnime-test' const SCREENSHOT_PATH = './screenshots/' const BINPATH = './node_modules/nightwatch/bin/' diff --git a/package.json b/package.json index 86fdc46..7b19362 100644 --- a/package.json +++ b/package.json @@ -10,11 +10,11 @@ }, "license": "MIT", "scripts": { - "dev": "cross-env NODE_ENV=development electron main.js", + "dev": "NODE_ENV=development electron main.js", "dev:server": "node assets/serverStart.js", "start": "NODE_ENV=production electron main.js", "bstart": "npm run build && npm start", - "build": "rimraf dist && npm run build:client && npm run build:server", + "build": "rimraf public && npm run build:client && npm run build:server", "build:client": "NODE_ENV=production webpack --config webpack/webpack.client.config.js --progress --hide-modules", "build:server": "NODE_ENV=production webpack --config webpack/webpack.server.config.js --progress --hide-modules", "cloc": "cloc $(git ls-files | grep -vE \".mkv|mp4|lock\")", @@ -35,8 +35,10 @@ }, "dependencies": { "axios": "^0.16.2", - "compression": "^1.6.2", + "babel-core": "^6.25.0", + "babel-runtime": "^6.23.0", "colors": "^1.1.2", + "compression": "^1.6.2", "express": "^4.15.3", "horrible-api": "^1.0.5", "lodash": "^4.17.4", @@ -48,14 +50,13 @@ "vue": "^2.4.2", "vue-router": "^2.7.0", "vue-server-renderer": "^2.4.2", - "vuetify": "^0.14.5", + "vuetify": "^0.14.6", "vuex": "^2.3.1", "vuex-router-sync": "^4.1.2" }, "devDependencies": { "autoprefixer": "^7.1.1", "ava": "^0.19.1", - "babel-core": "^6.22.1", "babel-loader": "^7.0.0", "babel-plugin-add-module-exports": "^0.2.1", "babel-plugin-transform-runtime": "^6.22.0", diff --git a/pages/index.vue b/pages/index.vue index 17619e7..0492989 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -191,7 +191,7 @@ console.log(`[${(new Date()).toLocaleTimeString()}]: Opening modal`) this.modalTitle = title - this.modalText = text + this.modalText = text + 'Blabla' this.modal = true }, @@ -204,8 +204,8 @@ axios.post('download', { name: name, quality: quality, - fromEp: -Infinity, - untilEp: Infinity, + fromEp: 0, + untilEp: 20000, fansub: fansub, choice: 'si' }).then(({data}) => { diff --git a/static/favicon-32x32.png b/static/favicon-32x32.png deleted file mode 100644 index 91155ba..0000000 Binary files a/static/favicon-32x32.png and /dev/null differ diff --git a/static/robots.txt b/static/robots.txt deleted file mode 100644 index 6f27bb6..0000000 --- a/static/robots.txt +++ /dev/null @@ -1,2 +0,0 @@ -User-agent: * -Disallow: \ No newline at end of file diff --git a/static/sitemap.xml b/static/sitemap.xml deleted file mode 100644 index d6818e3..0000000 --- a/static/sitemap.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - / - 2017-07-23 - daily - 1.0 - - diff --git a/test/nightwatch/main.test.js b/test/nightwatch/main.test.js index 757aa28..4bbacc1 100644 --- a/test/nightwatch/main.test.js +++ b/test/nightwatch/main.test.js @@ -3,25 +3,74 @@ */ require('colors') -const {readdirSync, unlinkSync, rmdirSync} = require('fs') +const {readdirSync, unlinkSync, rmdirSync, readFileSync} = require('fs') const {join} = require('path') +const path = require('path') const {userInfo} = require('os') +const LRU = require('lru-cache') +const express = require('express') +const compression = require('compression') +const resolve = file => path.resolve(__dirname, file) +const { createBundleRenderer } = require('vue-server-renderer') +const redirects = require('../../router/301.json') // We keep the nuxt and server instance // So we can close them at the end of the test let server = null -const uri = 'http://localhost:4000' +let renderer = null +const template = readFileSync(resolve('../../assets/index.template.html'), 'utf-8') +const uri = 'http://localhost:9200' const DIR = join(userInfo().homedir, '.KawAnime-test') +const serve = (path, cache) => express.static(resolve(path), { + maxAge: cache && 60 * 60 * 24 * 30 +}) + +const createRenderer = (bundle, options) => { + // https://github.com/vuejs/vue/blob/dev/packages/vue-server-renderer/README.md#why-use-bundlerenderer + return createBundleRenderer(bundle, Object.assign(options, { + template, + // for component caching + cache: LRU({ + max: 1000, + maxAge: 1000 * 60 * 15 + }), + // this is only needed when vue-server-renderer is npm-linked + basedir: resolve('./public'), + // performance + runInNewContext: false + })) +} + module.exports = { // adapted from: https://git.io/vodU0 before: function (browser, done) { - /** - * Server config - */ - done() + const app = express() - console.log(`KawAnime's server is at http://localhost:${uri}`.green) + const bundle = require('../../public/vue-ssr-server-bundle.json') + const clientManifest = require('../../public/vue-ssr-client-manifest.json') + renderer = createRenderer(bundle, { + clientManifest + }) + + console.log(renderer) + + app.use(compression({ threshold: 0 })) + app.use('/static', serve('./static', true)) + app.use('/public', serve('./public', true)) + + // Setup the api + require('../../server')(app) + + // 301 redirect for changed routes + Object.keys(redirects).forEach((k) => { + app.get(k, (req, res) => res.redirect(301, redirects[k])) + }) + + server = app.listen(9200, '0.0.0.0', () => { + console.log(`> server started at ${uri}`.green) + done() + }) }, 'Getting downloader page and downloading some anime': function (client) { client @@ -34,7 +83,7 @@ module.exports = { // adapted from: https://git.io/vodU0 .click('div.choose-magnets .input-group__input') .assert.visible('input[name="name-input"]') .click('input[name="name-input"]') - .setValue('input[name="name-input"]', 'rewrite') + .setValue('input[name="name-input"]', 'sakura trick') .assert.visible('input[name="from-ep-input"]') .click('input[name="from-ep-input"]') .setValue('input[name="from-ep-input"]', '3') diff --git a/webpack/setup-dev-server.js b/webpack/setup-dev-server.js index 94e1418..f45530a 100644 --- a/webpack/setup-dev-server.js +++ b/webpack/setup-dev-server.js @@ -1,8 +1,8 @@ const path = require('path') const webpack = require('webpack') const MFS = require('memory-fs') -const clientConfig = require('./webpack.client.config') -const serverConfig = require('./webpack.server.config') +const clientConfig = require(path.join(__dirname, 'webpack.client.config')) +const serverConfig = require(path.join(__dirname, 'webpack.server.config')) module.exports = function setupDevServer (app, cb) { let bundle, clientManifest diff --git a/webpack/vue-loader.config.js b/webpack/vue-loader.config.js index e4ae821..5a619b7 100644 --- a/webpack/vue-loader.config.js +++ b/webpack/vue-loader.config.js @@ -1,5 +1,5 @@ module.exports = { - extractCSS: process.env.NODE_ENV === 'production', + extractCSS: !process.env.NODE_ENV === 'development', preserveWhitespace: false, postcss: [ require('autoprefixer')({ diff --git a/webpack/webpack.client.config.js b/webpack/webpack.client.config.js index 4f706e3..c365768 100644 --- a/webpack/webpack.client.config.js +++ b/webpack/webpack.client.config.js @@ -1,7 +1,6 @@ const webpack = require('webpack') const merge = require('webpack-merge') const base = require('./webpack.base.config') -// const SWPrecachePlugin = require('sw-precache-webpack-plugin') const VueSSRClientPlugin = require('vue-server-renderer/client-plugin') const config = merge(base, {