You are not logged in.
Pages: 1
I built an events calendar using fullcalendar.io and I use a node server/postgresql database to store and access the events for persistence. Currently I am hosting a version of it on gitlab, but it only includes the calendar, and not the node/database instance. I haven't found much as to deploying databases via gitlab pages, so I am curious then if anyone here has done it, or is willing to point me in the right direction?
FWIW I am using a simple .gitlab-ci.yml for CI/CD, here are some relevant files, please let me know if there are any others I should include:
# .gitlab-ci.yml
image: node:latest
stages:
- build
- deploy
cache:
paths:
- node_modules/
install_dependencies:
stage: build
script:
- cd website
- npm install
- npm run build
artifacts:
paths:
- node_modules/
only:
- master
pages:
stage: deploy
script:
- npm install
- npm run build
- mkdir .public
- cp -r * .public
- mv .public public
artifacts:
paths:
- node_modules
- public
only:
- master
#server.js
const express = require('express');
const app = express();
const fs = require('fs');
const bodyParser = require('body-parser');
const db = require('./queries');
const cors = require('cors');
app.use(cors());
app.use(bodyParser.json())
app.use(
bodyParser.urlencoded({
extended: true,
})
)
app.get('/events', db.getEvents)
app.post('/events', db.postEvents)
var server = app.listen(8081, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
})
# queris.js
const Pool = require('pg').Pool
const pool = new Pool({
user: 'cal',
host: 'localhost',
database: 'eventsapi',
password: 'password',
port: 5432,
})
const getEvents = (request, response) => {
pool.query('SELECT (title, starttime) FROM events', (error, results) => {
if (error) {
throw error
}
response.status(200).json(results.rows)
})
}
const postEvents = (request, response) => {
const { title, starttime } = request.body
pool.query('INSERT INTO events (title, starttime) VALUES ($1, $2)', [title, starttime], (error, results) => {
if(error) {
throw error
}
response.status(201).send('User added')
})
}
module.exports = {
getEvents,
postEvents,
}
It's also a small enough application, that I considered using a file to store events, and reading/writing the file for loading/saving events, though I am not sure how I would deploy that to gitlab either.
Also also: My apologies if this is the incorrect sub-forum, if so please move to the correct one
"Dr. Madden, why don't the natural numbers include 0?" -me
"....... Take a philosophy course" -Dr. Madden
Offline
Pages: 1