Init
This commit is contained in:
commit
bcade66f5d
24
Dockerfile
Normal file
24
Dockerfile
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Create image based on the official Node image from dockerhub
|
||||||
|
FROM node:latest
|
||||||
|
|
||||||
|
# Create app directory
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
# Copy dependency definitions
|
||||||
|
COPY package.json ./package.json
|
||||||
|
COPY package-lock.json ./package-lock.json
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
#RUN npm set progress=false \
|
||||||
|
# && npm config set depth 0 \
|
||||||
|
# && npm i install
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
# Get all the code needed to run the app
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Expose the port the app runs in
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Serve the app
|
||||||
|
CMD ["npm", "start", "3000"]
|
2052
package-lock.json
generated
Normal file
2052
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
21
package.json
Normal file
21
package.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "summercamp-p6",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "supermarketServer.js",
|
||||||
|
"dependencies": {
|
||||||
|
"dotenv": "^16.0.0",
|
||||||
|
"ejs": "3.1.9",
|
||||||
|
"express": "4.18.2",
|
||||||
|
"http": "0.0.1-security",
|
||||||
|
"two.js": "latest"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"devDependencies": {
|
||||||
|
"nodemon": "^3.0.2"
|
||||||
|
}
|
||||||
|
}
|
3
readme
Normal file
3
readme
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Build docker container: sudo docker build -t typing .
|
||||||
|
# Run docker container: docker run -d -p 0.0.0.0:3000:3000 typing --name type
|
||||||
|
sudo docker run -dp 127.0.0.1:3000:3000 typing
|
77
server.js
Normal file
77
server.js
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
const express= require("express");
|
||||||
|
const path = require("path");
|
||||||
|
const app = express();
|
||||||
|
const fs = require(`fs`);
|
||||||
|
const readline = require('readline');
|
||||||
|
require("dotenv").config({ path: path.resolve(__dirname, '.env') })
|
||||||
|
const bodyParser = require("body-parser");
|
||||||
|
|
||||||
|
port = -1;
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
if (process.argv.length == 3) {
|
||||||
|
port = process.argv[2];
|
||||||
|
} else {
|
||||||
|
console.log("Usage summerCampSerever.js port");
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
expressSetup();
|
||||||
|
|
||||||
|
let rl = readline.createInterface({
|
||||||
|
input: process.stdin,
|
||||||
|
output: process.stdout,
|
||||||
|
prompt: 'Type itemsList or stop to shutdown the server: ' // Set a custom prompt
|
||||||
|
});
|
||||||
|
rl.prompt();
|
||||||
|
rl.on('line', (line) => {
|
||||||
|
// Process the entered command
|
||||||
|
processCommand(line.trim());
|
||||||
|
|
||||||
|
// Display the prompt again
|
||||||
|
rl.prompt();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function expressSetup() {
|
||||||
|
app.set("views", path.resolve(__dirname, "templates"));
|
||||||
|
app.use(bodyParser.urlencoded({extended:false}));
|
||||||
|
app.use(express.static('assets'));
|
||||||
|
|
||||||
|
/* view/templating engine */
|
||||||
|
app.set("view engine", "ejs");
|
||||||
|
|
||||||
|
/* Root */
|
||||||
|
app.get("/", (request, response) => {
|
||||||
|
response.render("index");
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get("/stats", (request, response) => {
|
||||||
|
response.render("myStats");
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get("/leaderboard", (request, response) => {
|
||||||
|
response.render("leaderboard");
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get("/about", (request, response) => {
|
||||||
|
response.render("about");
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
app.listen(port);
|
||||||
|
}
|
||||||
|
|
||||||
|
function processCommand(command) {
|
||||||
|
if (command == "stop") {
|
||||||
|
console.log("Shutting down the server");
|
||||||
|
process.exit(0);
|
||||||
|
} else if (command == "itemsList") {
|
||||||
|
console.log(itemsList.itemList);
|
||||||
|
} else {
|
||||||
|
console.log(`Invalid command: ${command}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
Loading…
x
Reference in New Issue
Block a user