ddstats-server/index.js
2021-10-31 20:46:43 +01:00

28 lines
761 B
JavaScript

import express from 'express'
import dotenv from 'dotenv'
import api from './api/api.js'
import { generateDB } from "./db/generate.js"
import { sqlite, dbInit } from "./db/init.js"
import { ddnssStart, scrapeServer } from './ddnss/handler.js'
//import tasks from './db/tasks.js'
/* Read the .env file */
dotenv.config()
/* Init db */
dbInit()
/* check if the table points exists */
const exists = sqlite.prepare(`SELECT count(*) as a FROM sqlite_master WHERE type='table' AND name='points'`).get()
/* Generate the DB if false */
if(!exists.a)
generateDB()
/* Init express */
const Server = express()
Server.use('/api', api)
Server.listen(process.env.PORT, () => console.log(`Server started and listening on port ${process.env.PORT}.`))
//ddnssStart()