Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Add support for public static files. Closes #2234

Gabe Kangas877a046eb21a
diff --git a/router/router.go b/router/router.go
index 2aa8a6aebe..7da2af2b7b 100644
--- a/router/router.go
+++ b/router/router.go
@@ -373,6 +373,9 @@ func Start() error {
chat.HandleClientConnection(w, r)
})
+ // Optional public static files
+ http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir("./public"))))
+
port := config.WebServerPort
ip := config.WebServerIP
diff --git a/test/automated/api/publicstatic.test.js b/test/automated/api/publicstatic.test.js
new file mode 100644
index 0000000000..32b40ce075
--- /dev/null
+++ b/test/automated/api/publicstatic.test.js
@@ -0,0 +1,31 @@
+var request = require('supertest');
+request = request('http://127.0.0.1:8080');
+const fs = require('fs');
+const path = require('path');
+
+function randomString(length) {
+ return Math.random().toString(36).substring(length);
+}
+
+const filename = `${randomString(20)}.txt`;
+
+test('public static file should not exist', async (done) => {
+ await request.get(`/public/${filename}`).expect(404);
+
+ done();
+});
+
+test('public static file should exist', async (done) => {
+ // make public static files directory
+ try {
+ fs.mkdirSync(path.join(__dirname, '../../../public/'));
+ fs.writeFileSync(
+ path.join(__dirname, `../../../public/${filename}`),
+ 'hello world'
+ );
+ } catch (e) {}
+
+ await request.get(`/public/${filename}`).expect(200);
+
+ done();
+});