Use pug
This commit is contained in:
@@ -18,6 +18,8 @@ import { Maybe, None, Some } from "monet";
|
||||
import path from "path";
|
||||
import { QueryFile } from "pg-promise";
|
||||
|
||||
const sqlDir = path.join(process.cwd(), "sql");
|
||||
|
||||
const migrations = {
|
||||
applied: sql("migrations/applied.sql"),
|
||||
apply: sql("migrations/apply.sql"),
|
||||
@@ -42,13 +44,13 @@ export { migrations, users };
|
||||
|
||||
/** Helper for linking to external query files */
|
||||
function sql(file: string): QueryFile {
|
||||
const fullPath = path.join(__dirname, file);
|
||||
const fullPath = path.join(sqlDir, file);
|
||||
|
||||
return new QueryFile(fullPath, { minify: true });
|
||||
}
|
||||
|
||||
function ifExists(file: string): Maybe<string> {
|
||||
const fullPath = path.join(__dirname, file);
|
||||
const fullPath = path.join(sqlDir, file);
|
||||
if (existsSync(fullPath)) {
|
||||
return Some(file);
|
||||
} else {
|
||||
@@ -57,7 +59,7 @@ function ifExists(file: string): Maybe<string> {
|
||||
}
|
||||
|
||||
function subdirs(dir: string): string[] {
|
||||
const fullPath = path.join(__dirname, dir);
|
||||
const fullPath = path.join(sqlDir, dir);
|
||||
return readdirSync(fullPath, { withFileTypes: true })
|
||||
.filter(dirent => dirent.isDirectory)
|
||||
.map(dirent => dirent.name)
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
SELECT id, name, applied_at FROM migrations ORDER BY applied_at
|
||||
@@ -1 +0,0 @@
|
||||
INSERT INTO migrations (name) VALUES ($1);
|
||||
@@ -1,5 +0,0 @@
|
||||
CREATE TABLE IF NOT EXISTS migrations (
|
||||
id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
name text UNIQUE NOT NULL,
|
||||
applied_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
@@ -1 +0,0 @@
|
||||
DROP FUNCTION set_updated_timestamp;
|
||||
@@ -1,11 +0,0 @@
|
||||
CREATE OR REPLACE FUNCTION set_updated_timestamp()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
IF row(NEW.*) IS DISTINCT FROM row(OLD.*) THEN
|
||||
NEW.updated_at = now();
|
||||
RETURN NEW;
|
||||
ELSE
|
||||
RETURN OLD;
|
||||
END IF;
|
||||
END;
|
||||
$$ language 'plpgsql';
|
||||
@@ -1 +0,0 @@
|
||||
DROP TABLE users;
|
||||
@@ -1,9 +0,0 @@
|
||||
CREATE TABLE users (
|
||||
id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
email text NOT NULL UNIQUE,
|
||||
encrypted_password text NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TRIGGER set_users_updated BEFORE UPDATE ON users FOR EACH ROW EXECUTE PROCEDURE set_updated_timestamp();
|
||||
@@ -1 +0,0 @@
|
||||
INSERT INTO users (email, encrypted_password) VALUES ($1, $2) RETURNING id
|
||||
@@ -1 +0,0 @@
|
||||
SELECT id, encrypted_password FROM users WHERE email=$1
|
||||
@@ -16,8 +16,7 @@
|
||||
import { server as graphqlServer } from "@kredens/api";
|
||||
import { db } from "@kredens/db";
|
||||
import logger from "@kredens/logger";
|
||||
import authRouter from "@kredens/routes/auth";
|
||||
import indexRouter from "@kredens/routes/index";
|
||||
import indexRouter from "@kredens/routes/";
|
||||
import cookieParser from "cookie-parser";
|
||||
import express from "express";
|
||||
import pinoExpress from "express-pino-logger";
|
||||
@@ -38,9 +37,9 @@ async function main() {
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: false }));
|
||||
app.use(cookieParser());
|
||||
app.set("view engine", "pug");
|
||||
|
||||
app.use("/", indexRouter);
|
||||
app.use("/auth/", authRouter);
|
||||
server.applyMiddleware({ app, path: "/graphql" });
|
||||
|
||||
app.use((req, res, next) => {
|
||||
|
||||
24
src/routes/home.ts
Normal file
24
src/routes/home.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (C) 2019 ModZero <modzero@modzero.xyz>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import express from "express";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/", (req, res, next) => {
|
||||
res.render("index", { title: "Hey", message: "Hi!" });
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -1,24 +1,10 @@
|
||||
// Copyright (C) 2019 ModZero <modzero@modzero.xyz>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import express from "express";
|
||||
import authRouter from "./auth";
|
||||
import homeRouter from "./home";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/", (req, res, next) => {
|
||||
res.send("Hello, world!");
|
||||
});
|
||||
router.use("/", homeRouter);
|
||||
router.use("/auth", authRouter);
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user