diff --git a/app.js b/app.js index 9513e68..9fb516d 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,6 @@ const express = require("express"); const fs = require("fs"); -const path = require("path"); +const join = require("path").join; const morgan = require("morgan"); const bodyParser = require("body-parser"); const sqlite3 = require("sqlite3").verbose(); @@ -37,12 +37,13 @@ const db = new sqlite3.Database(config.db_path, (err) => { }); var accessLogStream = fs.createWriteStream( - path.join(__dirname, "log", "access.log"), + join(__dirname, "log", "access.log"), { flags: "a" }, ); app.use(bodyParser.json()); app.use(morgan("combined", { stream: accessLogStream })); +app.use(express.static(join(__dirname, './wwwroot'))); var animals; // check and load animals into redis @@ -77,10 +78,7 @@ try { // Serve the HTML file app.get("/", (req, res) => { - res.sendFile(__dirname + "/index.html"); -}); -app.get("/asset/frontend.js", (req, res) => { - res.sendFile(__dirname + "/asset/frontend.js"); + res.sendFile(__dirname + "/wwwroot/index.html"); }); // Route to get a random animal name diff --git a/app.test.js b/app.test.js index 6450016..c333dde 100644 --- a/app.test.js +++ b/app.test.js @@ -9,6 +9,20 @@ describe('GET /', () => { //expect(response.body.message).toBe('Hello, World!'); }); }); +describe('GET /index.html', () => { + it('should respond with 200 status', async () => { + const response = await request(app).get('/index.html'); + expect(response.statusCode).toBe(200); + //expect(response.body.message).toBe('Hello, World!'); + }); +}); +describe('GET /what.html', () => { + it('should respond with 200 status', async () => { + const response = await request(app).get('/what.html'); + expect(response.statusCode).toBe(200); + //expect(response.body.message).toBe('Hello, World!'); + }); +}); describe('GET /asset/frontend.js', () => { it('should respond with 200 status', async () => { diff --git a/asset/frontend.js b/wwwroot/asset/frontend.js similarity index 100% rename from asset/frontend.js rename to wwwroot/asset/frontend.js diff --git a/index.html b/wwwroot/index.html similarity index 87% rename from index.html rename to wwwroot/index.html index 2e985cf..c52cdf0 100644 --- a/index.html +++ b/wwwroot/index.html @@ -20,6 +20,12 @@
+