Skip to content

Commit

Permalink
add nostatic option to demo-server
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Dec 11, 2023
1 parent ce30895 commit 3ab8d0c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions demo-server/demo-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ const WebSocket = require('ws')
const http = require('http')
const StaticServer = require('node-static').Server
const setupWSConnection = require('y-websocket/bin/utils').setupWSConnection
const env = require('lib0/environment')
const nostatic = env.hasParam('--nostatic')

const production = process.env.PRODUCTION != null
const port = process.env.PORT || 3000

const staticServer = new StaticServer('../', { cache: production ? 3600 : false, gzip: production })
const staticServer = nostatic ? null : new StaticServer('../', { cache: production ? 3600 : false, gzip: production })

const server = http.createServer((request, response) => {
if (!(request.url || '').startsWith('/ws/')) {
if (staticServer && !(request.url || '').startsWith('/ws/')) {
request.addListener('end', () => {
staticServer.serve(request, response)
}).resume()
Expand All @@ -27,4 +29,4 @@ wss.on('connection', (conn, req) => {

server.listen(port, '0.0.0.0')

console.log(`Listening to http://localhost:${port} ${production ? '(production)' : ''}`)
console.log(`Listening to http://localhost:${port} (${production ? 'production + ' : ''} ${nostatic ? 'no static content' : 'serving static content'})`)
3 changes: 2 additions & 1 deletion demo-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"url": "https://github.com/sponsors/dmonad"
},
"scripts": {
"start": "export PRODUCTION=1; node ./demo-server.js"
"start": "export PRODUCTION=1; node ./demo-server.js",
"start:nostatic": "export PRODUCTION=1; node ./demo-server.js --nostatic"
},
"author": "Kevin Jahns <[email protected]",
"license": "MIT",
Expand Down

0 comments on commit 3ab8d0c

Please sign in to comment.