From 87765ba2c019e8ab138d2ef660cb32ba469d2ce5 Mon Sep 17 00:00:00 2001 From: lesion Date: Mon, 22 Aug 2022 17:18:00 +0200 Subject: [PATCH] startup --- nuxt.config.ts | 6 +++--- server/controller.js | 4 ++-- server/startup.js | 5 +++++ 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 server/startup.js diff --git a/nuxt.config.ts b/nuxt.config.ts index d680623..91e3700 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -6,10 +6,10 @@ import serveStatic from 'serve-static' // https://v3.nuxtjs.org/api/configuration/nuxt.config export default defineNuxtConfig({ ssr: true, + nitro: { + plugins: ['~/server/startup.js'], + }, buildModules: ['@nuxtjs/tailwindcss', 'unplugin-icons/nuxt', '@nuxtjs/svg'], - serverMiddleware: [ - { path: '/imgs', handler: serveStatic(__dirname + '/imgs') } - ], vite: { plugins: [ UnpluginComponentsVite({ diff --git a/server/controller.js b/server/controller.js index 912d5b1..22b68b0 100644 --- a/server/controller.js +++ b/server/controller.js @@ -4,10 +4,10 @@ import { v4 } from 'uuid' const db = new Database('./cosette.db') -function load() { +export function load() { db.pragma('journal_mode = WAL') db.exec('CREATE TABLE IF NOT EXISTS cosette (uuid TEXT PRIMARY KEY, name TEXT NOT NULL, description TEXT, tags TEXT, images TEXT, updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP)') - db.exec('CREATE INDEX cosette_updated_at_index ON cosette (updatedAt)') + db.exec('CREATE INDEX IF NOT EXISTS cosette_updated_at_index ON cosette (updatedAt)') db.exec('CREATE TABLE IF NOT EXISTS chan (uuid TEXT PRIMARY KEY, cosetta_uuid REFERENCES cosette(uuid), message TEXT, updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP)') } // TODO: da gestire in qualche modo all'avvio diff --git a/server/startup.js b/server/startup.js new file mode 100644 index 0000000..6fdd3ba --- /dev/null +++ b/server/startup.js @@ -0,0 +1,5 @@ +import { load } from '../server/controller' + +export default () => { + load() +}