From 4f12994bca33f4790076cc70139668d43caa406b Mon Sep 17 00:00:00 2001 From: b1ek Date: Mon, 20 Feb 2023 00:19:46 +1000 Subject: [PATCH] add guestbook --- README.md | 7 ---- config/config.json | 30 +++++++-------- index.js | 7 +++- migrations/20230219070939-create-guestbook.js | 38 ++++++++++++++----- models/index.js | 18 ++++++++- public/static/main.css | 12 +++++- routes/guestbook.js | 3 ++ view/layout/main.pug | 17 ++++++--- 8 files changed, 90 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 5846b2d..035af8d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,2 @@ # homepage.js This is a rewrite of my current website to Express.JS. - -# This was aborted. -With focusing on code structure & performance, I decided -to rewrite the website into JavaScript, but as it turned out, -i can't provide enough for my satisfaction with ExpressJS. - -I am re writing this to Go & atreugo diff --git a/config/config.json b/config/config.json index 0f858c6..6872d5e 100644 --- a/config/config.json +++ b/config/config.json @@ -1,23 +1,23 @@ { "development": { - "username": "root", - "password": null, - "database": "database_development", - "host": "127.0.0.1", - "dialect": "mysql" + "username": "homepage", + "password": "homepage", + "database": "homepage", + "host": "db", + "dialect": "postgres" }, "test": { - "username": "root", - "password": null, - "database": "database_test", - "host": "127.0.0.1", - "dialect": "mysql" + "username": "homepage", + "password": "homepage", + "database": "homepage", + "host": "db", + "dialect": "postgres" }, "production": { - "username": "root", - "password": null, - "database": "database_production", - "host": "127.0.0.1", - "dialect": "mysql" + "username": "homepage", + "password": "homepage", + "database": "homepage", + "host": "db", + "dialect": "postgres" } } diff --git a/index.js b/index.js index 66b745b..651d146 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,12 @@ // do startup jobs require('./startup'); -if (process.env.APP_DEBUG == 'true') process.env.DEBUG = '*/*'; +if (process.env.APP_DEBUG == 'true') { + process.env.DEBUG = '*/*'; + process.env.NODE_ENV = 'development'; +} else { + process.env.NODE_ENV = 'production'; +} const express = require('express'); const app = express(); diff --git a/migrations/20230219070939-create-guestbook.js b/migrations/20230219070939-create-guestbook.js index 2a85f53..5b761f5 100644 --- a/migrations/20230219070939-create-guestbook.js +++ b/migrations/20230219070939-create-guestbook.js @@ -1,27 +1,45 @@ 'use strict'; /** @type {import('sequelize-cli').Migration} */ module.exports = { - async up(queryInterface, Sequelize) { + async up(queryInterface, DataTypes) { await queryInterface.createTable('Guestbooks', { id: { - allowNull: false, - autoIncrement: true, + type: DataTypes.BIGINT(11), primaryKey: true, - type: Sequelize.INTEGER - }, - id: { - type: Sequelize.BIGINT + autoIncrement: true, + allowNull: false }, name: { - type: Sequelize.TEXT + type: DataTypes.TEXT, + allowNull: false + }, + email: DataTypes.TEXT, + text: { + type: DataTypes.TEXT, + allowNull: false + }, + hidemail: { + type: DataTypes.BOOLEAN, + allowNull: false + }, + ip: { + type: DataTypes.TEXT, + allowNull: false + }, + hidden: { + type: DataTypes.BOOLEAN, + allowNull: false + }, + time: { + type: DataTypes.BIGINT }, createdAt: { allowNull: false, - type: Sequelize.DATE + type: DataTypes.DATE }, updatedAt: { allowNull: false, - type: Sequelize.DATE + type: DataTypes.DATE } }); }, diff --git a/models/index.js b/models/index.js index 024200e..43ecfb2 100644 --- a/models/index.js +++ b/models/index.js @@ -5,10 +5,24 @@ const path = require('path'); const Sequelize = require('sequelize'); const process = require('process'); const basename = path.basename(__filename); -const env = process.env.NODE_ENV || 'development'; -const config = require(__dirname + '/../config/config.json')[env]; +const env = process.env.NODE_ENV || 'production'; +let config = require(__dirname + '/../config/config.json')[env]; const db = {}; +const { + DB_PASSWORD, + DB_USERNAME, + DB_DATABASE, + DB_HOSTNAME +} = process.env; +config = { + ...config, + username: DB_USERNAME || config.username, + password: DB_PASSWORD || config.password, + database: DB_DATABASE || config.database, + host: DB_HOSTNAME || config.host +} + let sequelize; if (config.use_env_variable) { sequelize = new Sequelize(process.env[config.use_env_variable], config); diff --git a/public/static/main.css b/public/static/main.css index dece447..4058314 100644 --- a/public/static/main.css +++ b/public/static/main.css @@ -43,7 +43,9 @@ a:visited { list-style: none; padding: 0; font-size: 11pt; - padding-top: 32px; + padding-top: 36px; + padding-left: 4px; + line-height: 125%; } .main_contents { padding: 16px 12px; @@ -62,4 +64,12 @@ a:visited { hr { border: 0; border-bottom: 1px solid #C2C4C2; +} + +a { + font-weight: bold; + font-size: 95%; + text-decoration: none; + color:#2353ad; + font-family: 'Open Sans' 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } \ No newline at end of file diff --git a/routes/guestbook.js b/routes/guestbook.js index 63526e3..ba24ecd 100644 --- a/routes/guestbook.js +++ b/routes/guestbook.js @@ -1,4 +1,5 @@ const Helpers = require('../helpers'); +const Sequelize = require('../models'); async function handler(req, res, next) { try { @@ -32,6 +33,8 @@ async function submit(req, res) { name, email, message, hidemail }); + // console.log(Sequelize.Guestbook); + return; } diff --git a/view/layout/main.pug b/view/layout/main.pug index 15ed973..9bee7c3 100644 --- a/view/layout/main.pug +++ b/view/layout/main.pug @@ -4,7 +4,9 @@ block root let routes = { "Main page": '/', "Projects": "/project", - "About me": "/about" + "About me": "/about", + "hr": "hr", + "Guestbook": "/guestbook" } doctype html @@ -24,11 +26,14 @@ html hr(class='flag_hr') ul each route, name in routes - li - if current_route == route - | > #{name} - else - a(href=route) #{name} + if (route == 'hr') + li
+ else + li(style='padding-left:4px') + if current_route == route + | > #{name} + else + a(href=route) #{name} td(class='main_contents') block content block foot