add guestbook

This commit is contained in:
b1ek 2023-02-20 00:19:46 +10:00
parent 8bad9f7c83
commit 4f12994bca
8 changed files with 90 additions and 42 deletions

View File

@ -1,9 +1,2 @@
# homepage.js # homepage.js
This is a rewrite of my current website to Express.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

View File

@ -1,23 +1,23 @@
{ {
"development": { "development": {
"username": "root", "username": "homepage",
"password": null, "password": "homepage",
"database": "database_development", "database": "homepage",
"host": "127.0.0.1", "host": "db",
"dialect": "mysql" "dialect": "postgres"
}, },
"test": { "test": {
"username": "root", "username": "homepage",
"password": null, "password": "homepage",
"database": "database_test", "database": "homepage",
"host": "127.0.0.1", "host": "db",
"dialect": "mysql" "dialect": "postgres"
}, },
"production": { "production": {
"username": "root", "username": "homepage",
"password": null, "password": "homepage",
"database": "database_production", "database": "homepage",
"host": "127.0.0.1", "host": "db",
"dialect": "mysql" "dialect": "postgres"
} }
} }

View File

@ -1,7 +1,12 @@
// do startup jobs // do startup jobs
require('./startup'); 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 express = require('express');
const app = express(); const app = express();

View File

@ -1,27 +1,45 @@
'use strict'; 'use strict';
/** @type {import('sequelize-cli').Migration} */ /** @type {import('sequelize-cli').Migration} */
module.exports = { module.exports = {
async up(queryInterface, Sequelize) { async up(queryInterface, DataTypes) {
await queryInterface.createTable('Guestbooks', { await queryInterface.createTable('Guestbooks', {
id: { id: {
allowNull: false, type: DataTypes.BIGINT(11),
autoIncrement: true,
primaryKey: true, primaryKey: true,
type: Sequelize.INTEGER autoIncrement: true,
}, allowNull: false
id: {
type: Sequelize.BIGINT
}, },
name: { 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: { createdAt: {
allowNull: false, allowNull: false,
type: Sequelize.DATE type: DataTypes.DATE
}, },
updatedAt: { updatedAt: {
allowNull: false, allowNull: false,
type: Sequelize.DATE type: DataTypes.DATE
} }
}); });
}, },

View File

@ -5,10 +5,24 @@ const path = require('path');
const Sequelize = require('sequelize'); const Sequelize = require('sequelize');
const process = require('process'); const process = require('process');
const basename = path.basename(__filename); const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development'; const env = process.env.NODE_ENV || 'production';
const config = require(__dirname + '/../config/config.json')[env]; let config = require(__dirname + '/../config/config.json')[env];
const db = {}; 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; let sequelize;
if (config.use_env_variable) { if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config); sequelize = new Sequelize(process.env[config.use_env_variable], config);

View File

@ -43,7 +43,9 @@ a:visited {
list-style: none; list-style: none;
padding: 0; padding: 0;
font-size: 11pt; font-size: 11pt;
padding-top: 32px; padding-top: 36px;
padding-left: 4px;
line-height: 125%;
} }
.main_contents { .main_contents {
padding: 16px 12px; padding: 16px 12px;
@ -62,4 +64,12 @@ a:visited {
hr { hr {
border: 0; border: 0;
border-bottom: 1px solid #C2C4C2; 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;
} }

View File

@ -1,4 +1,5 @@
const Helpers = require('../helpers'); const Helpers = require('../helpers');
const Sequelize = require('../models');
async function handler(req, res, next) { async function handler(req, res, next) {
try { try {
@ -32,6 +33,8 @@ async function submit(req, res) {
name, email, message, hidemail name, email, message, hidemail
}); });
// console.log(Sequelize.Guestbook);
return; return;
} }

View File

@ -4,7 +4,9 @@ block root
let routes = { let routes = {
"Main page": '/', "Main page": '/',
"Projects": "/project", "Projects": "/project",
"About me": "/about" "About me": "/about",
"hr": "hr",
"Guestbook": "/guestbook"
} }
doctype html doctype html
@ -24,11 +26,14 @@ html
hr(class='flag_hr') hr(class='flag_hr')
ul ul
each route, name in routes each route, name in routes
li if (route == 'hr')
if current_route == route li <hr/>
| > #{name} else
else li(style='padding-left:4px')
a(href=route) #{name} if current_route == route
| > #{name}
else
a(href=route) #{name}
td(class='main_contents') td(class='main_contents')
block content block content
block foot block foot