mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2025-04-09 04:50:57 -04:00
fix: create tables
This commit is contained in:
parent
77832d73de
commit
0a21838c91
3 changed files with 14 additions and 7 deletions
nodejs-mini-message-board
|
@ -8,8 +8,6 @@ RUN npm install . && chown nobody:nobody /app
|
|||
|
||||
COPY --chown=nobody:nobody ./src /app/src
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
USER nobody
|
||||
|
||||
ENTRYPOINT ["node"]
|
||||
|
|
|
@ -5,8 +5,6 @@ const path = require("node:path");
|
|||
const port = 3000;
|
||||
|
||||
const { indexRouter } = require("./routes/indexRouter");
|
||||
//const { msgRouter } = require("./routes/msgRouter");
|
||||
//
|
||||
|
||||
app.set("views", path.join(__dirname, "views"));
|
||||
app.set("view engine", "ejs");
|
||||
|
@ -16,15 +14,14 @@ app.use(express.static(assetsPath));
|
|||
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
//Logging
|
||||
app.use((req, res, next) => {
|
||||
req.time = new Date(Date.now()).toISOString();
|
||||
console.log(req.time, req.method, req.hostname, req.path);
|
||||
console.log(req.time, req.method, req.hostname, req.path, req.ips);
|
||||
next();
|
||||
});
|
||||
|
||||
app.use("/", indexRouter);
|
||||
//app.use("/new", msgRouter);
|
||||
//
|
||||
|
||||
const server = app.listen(port, () => {
|
||||
console.log(`Webserver running on ${port}.`);
|
||||
|
|
|
@ -17,6 +17,18 @@ stat(dbDirPath, (err, stats) => {
|
|||
makeDirectory(dbDirPath);
|
||||
}
|
||||
});
|
||||
|
||||
const db = new sqlite3.Database(dbPath);
|
||||
db.serialize(() => {
|
||||
const SQL = `
|
||||
CREATE TABLE IF NOT EXISTS messages (
|
||||
id INTEGER PRIMARY KEY ASC,
|
||||
message TEXT,
|
||||
username VARCHAR(25),
|
||||
date TEXT
|
||||
);
|
||||
`;
|
||||
db.exec(SQL);
|
||||
});
|
||||
|
||||
module.exports = db;
|
||||
|
|
Loading…
Add table
Reference in a new issue