Initial commit
commit
ce518aeeb5
|
@ -0,0 +1,4 @@
|
|||
Dockerfile
|
||||
.dockerignore
|
||||
.git
|
||||
.gitignore
|
|
@ -0,0 +1,2 @@
|
|||
node_modules/
|
||||
.env
|
|
@ -0,0 +1,8 @@
|
|||
FROM node:latest
|
||||
|
||||
WORKDIR /home/app
|
||||
USER node
|
||||
ENV PORT 3000
|
||||
EXPOSE 3000
|
||||
|
||||
CMD npm start
|
|
@ -0,0 +1,10 @@
|
|||
CREATE TABLE states (
|
||||
state varchar UNIQUE NOT NULL,
|
||||
PRIMARY KEY(state)
|
||||
);
|
||||
|
||||
INSERT INTO states (state) VALUES
|
||||
('Requested'),
|
||||
('Rejected'),
|
||||
('Accepted'),
|
||||
('Learned');
|
|
@ -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)
|
||||
);
|
|
@ -0,0 +1,2 @@
|
|||
CREATE VIEW requests_vw AS
|
||||
SELECT * FROM requests WHERE state = 'Requested' ORDER BY score DESC;
|
|
@ -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
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"watch": ["src"],
|
||||
"ext": "ts",
|
||||
"ignore": ["src/**/*.spec.ts"],
|
||||
"exec": "ts-node ./src/app.ts"
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -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"
|
||||
}
|
||||
}
|
|
@ -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>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
body {
|
||||
padding: 0.5em 1em 2em 1em;
|
||||
text-align: center;
|
||||
font-family: sans-serif;
|
||||
}
|
|
@ -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}`);
|
||||
});
|
|
@ -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);
|
|
@ -0,0 +1,5 @@
|
|||
const { Pool } = require('pg');
|
||||
|
||||
const db = new Pool();
|
||||
|
||||
export = db;
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue