From b83b8dd5aef03084133c5983de6f312e7d1654b8 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Wed, 14 Nov 2018 15:27:47 +0100 Subject: [PATCH] add cli option to run without client --- package.json | 1 + server.ts | 7 +++++- server/tests/api/server/index.ts | 1 + server/tests/api/server/no-client.ts | 36 ++++++++++++++++++++++++++++ server/tests/utils/server/servers.ts | 4 ++-- 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 server/tests/api/server/no-client.ts diff --git a/package.json b/package.json index 3c77b93cb..3d25a9ab8 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "dev:server": "scripty", "dev:client": "scripty", "start": "node dist/server", + "start:server": "node dist/server --no-client", "update-host": "node ./dist/scripts/update-host.js", "create-transcoding-job": "node ./dist/scripts/create-transcoding-job.js", "create-import-video-file-job": "node ./dist/scripts/create-import-video-file-job.js", diff --git a/server.ts b/server.ts index 59fb820b4..51aa67638 100644 --- a/server.ts +++ b/server.ts @@ -16,6 +16,7 @@ import * as cookieParser from 'cookie-parser' import * as helmet from 'helmet' import * as useragent from 'useragent' import * as anonymize from 'ip-anonymize' +import * as cli from 'commander' process.title = 'peertube' @@ -98,6 +99,10 @@ import { VideosRedundancyScheduler } from './server/lib/schedulers/videos-redund // ----------- Command line ----------- +cli + .option('--no-client', 'Start PeerTube without client interface') + .parse(process.argv) + // ----------- App ----------- // Enable CORS for develop @@ -151,7 +156,7 @@ app.use('/', trackerRouter) app.use('/', staticRouter) // Client files, last valid routes! -app.use('/', clientsRouter) +if (cli.client) app.use('/', clientsRouter) // ----------- Errors ----------- diff --git a/server/tests/api/server/index.ts b/server/tests/api/server/index.ts index eeb8b7a28..78ab7e18b 100644 --- a/server/tests/api/server/index.ts +++ b/server/tests/api/server/index.ts @@ -6,3 +6,4 @@ import './jobs' import './reverse-proxy' import './stats' import './tracker' +import './no-client' diff --git a/server/tests/api/server/no-client.ts b/server/tests/api/server/no-client.ts new file mode 100644 index 000000000..6d6ce8532 --- /dev/null +++ b/server/tests/api/server/no-client.ts @@ -0,0 +1,36 @@ +import 'mocha' +import * as request from 'supertest' +import { + flushTests, + killallServers, + ServerInfo +} from '../../utils/index' +import { runServer } from '../../utils/server/servers' + +describe('Start and stop server without web client routes', function () { + let server: ServerInfo + + before(async function () { + this.timeout(30000) + + await flushTests() + + server = await runServer(1, {}, ['--no-client']) + }) + + it('Should fail getting the client', function () { + const req = request(server.url) + .get('/') + + return req.expect(404) + }) + + after(async function () { + killallServers([ server ]) + + // Keep the logs if the test failed + if (this['ok']) { + await flushTests() + } + }) +}) diff --git a/server/tests/utils/server/servers.ts b/server/tests/utils/server/servers.ts index 3c946db27..f358a21f1 100644 --- a/server/tests/utils/server/servers.ts +++ b/server/tests/utils/server/servers.ts @@ -69,7 +69,7 @@ function flushTests () { }) } -function runServer (serverNumber: number, configOverride?: Object) { +function runServer (serverNumber: number, configOverride?: Object, args = []) { const server: ServerInfo = { app: null, serverNumber: serverNumber, @@ -115,7 +115,7 @@ function runServer (serverNumber: number, configOverride?: Object) { } return new Promise(res => { - server.app = fork(join(__dirname, '..', '..', '..', '..', 'dist', 'server.js'), [], options) + server.app = fork(join(__dirname, '..', '..', '..', '..', 'dist', 'server.js'), args, options) server.app.stdout.on('data', function onStdout (data) { let dontContinue = false -- 2.41.0