Initial commit

pull/1/head
Duncan X Simpson 2020-06-24 21:34:53 +00:00
commit d89f985d34
16 changed files with 1755 additions and 0 deletions

4
.dockerignore Normal file
View File

@ -0,0 +1,4 @@
Dockerfile
.dockerignore
.git
.gitignore

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules/
.env

8
Dockerfile Normal file
View File

@ -0,0 +1,8 @@
FROM node:latest
WORKDIR /home/app
USER node
ENV PORT 3000
EXPOSE 3000
CMD npm start

10
db/00-states.sql Normal file
View File

@ -0,0 +1,10 @@
CREATE TABLE states (
state varchar UNIQUE NOT NULL,
PRIMARY KEY(state)
);
INSERT INTO states (state) VALUES
('Requested'),
('Rejected'),
('Accepted'),
('Learned');

9
db/10-requests.sql Normal file
View File

@ -0,0 +1,9 @@
CREATE TABLE requests (
id int GENERATED ALWAYS AS IDENTITY,
url varchar UNIQUE,
requester varchar NOT NULL,
score int DEFAULT 0,
state varchar NOT NULL DEFAULT 'Requested',
PRIMARY KEY(id),
FOREIGN KEY (state) REFERENCES states(state)
);

2
db/50-views.sql Normal file
View File

@ -0,0 +1,2 @@
CREATE VIEW requests_vw AS
SELECT * FROM requests WHERE state = 'Requested' ORDER BY score DESC;

20
docker-compose.yml Normal file
View File

@ -0,0 +1,20 @@
version: '3.8'
services:
app:
container_name: learn-request-queue
build: .
depends_on:
- db
volumes:
- .:/home/app
environment:
PGHOST: db
PGDATABASE: postgres
PGUSER: postgres
db:
container_name: learn-request-queue-db
image: postgres
environment:
POSTGRES_HOST_AUTH_METHOD: trust
volumes:
- ./db:/docker-entrypoint-initdb.d

6
nodemon.json Normal file
View File

@ -0,0 +1,6 @@
{
"watch": ["src"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "ts-node ./src/app.ts"
}

1622
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

21
package.json Normal file
View File

@ -0,0 +1,21 @@
{
"name": "learn-request-queue",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"express": "^4.17.1",
"pg": "^8.2.1"
},
"devDependencies": {
"@types/express": "^4.17.6",
"@types/node": "^14.0.14",
"@types/pg": "^7.14.3",
"nodemon": "^2.0.4",
"ts-node": "^8.10.2",
"typescript": "^3.9.5"
},
"scripts": {
"start": "nodemon"
}
}

12
public/index.html Normal file
View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<link rel=stylesheet href=style.css />
<title>Test Main Page</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT" crossorigin="anonymous"></script>
</head>
<body>
<h1>Test Main Page</h1>
</body>
</html>

5
public/style.css Normal file
View File

@ -0,0 +1,5 @@
body {
padding: 0.5em 1em 2em 1em;
text-align: center;
font-family: sans-serif;
}

13
src/app.ts Normal file
View File

@ -0,0 +1,13 @@
import * as config from "./config";
import express from "express";
import db from "./db";
const app = express();
app.use(express.static('public'));
app.use(express.json());
app.get("/test", (request, response) => response.send("Test"))
const server = app.listen(config.port, () => {
console.log(`Listening on port ${config.port}`);
});

6
src/config.ts Normal file
View File

@ -0,0 +1,6 @@
if (!process.env.PORT) {
console.log("Missing environment variable PORT");
process.exit(1);
}
export const port: number = parseInt(process.env.PORT as string, 10);

5
src/db.ts Normal file
View File

@ -0,0 +1,5 @@
const { Pool } = require('pg');
const db = new Pool();
export = db;

10
tsconfig.json Normal file
View File

@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}