Skip to content
Snippets Groups Projects
Commit e4ba9ab5 authored by Benguria Elguezabal, Gorka's avatar Benguria Elguezabal, Gorka
Browse files

public release

parents
Branches master
No related tags found
No related merge requests found
node_modules
index.js.bak
\ No newline at end of file
stages:
- build_and_push
- redeploy
build_and_push:
image: docker/compose:latest
stage: build_and_push
services:
- docker:dind
script:
- docker build -t mock-api-apply-to-stradins-university . --tag 094360380/wp4-mock-api-apply-to-stradins-university
- docker login docker.io -u "$DOCKER_REGISTRY_USER" -p "$DOCKER_REGISTRY_PASSWORD"
- docker push 094360380/wp4-mock-api-apply-to-stradins-university
tags:
- docker
only:
- kubernetes
redeploy_at_k8s:
image: alpine/k8s:1.21.5
stage: redeploy
script:
- kubectl config set-cluster local --server="${K8S_SERVER}"
- kubectl config set clusters.local.certificate-authority-data "${K8S_CERTIFICATE_AUTHORITY_DATA}"
- kubectl config set-credentials local --token="${K8S_USER_TOKEN}"
- kubectl config set-context local --cluster=local --user=local
- kubectl config use-context local
- kubectl --insecure-skip-tls-verify version
- kubectl get deployments ujse-mock-api-apply-to-stradins-university -n ujse-dev --insecure-skip-tls-verify
- kubectl rollout restart deployment ujse-mock-api-apply-to-stradins-university -n ujse-dev --insecure-skip-tls-verify
tags:
- docker
only:
- kubernetes
FROM node:16
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
#Application related arguments
CMD ["npm", "start"]
# APPLY-TO-UNIVERSITY-mock
## Description
This is a mocked API for Applying to university in LV.
## Installation for devs and starting the application
1. Install nodejs and npm
2. npm install
3. npm start
## building and starting the application on docker environment
1. docker build . -t mock-api-apply-to-university
2. docker run -p3333:3333 -d mock-api-apply-to-university
db.json 0 → 100644
{
"Course": [
{
"dropdownID": "Select course",
"data": [
{
"optionID": 0,
"optionVal": [
{
"locale": "en",
"value": "International Undergraduate"
},
{
"locale": "el",
"value": "---"
}
]
},
{
"optionID": 1,
"optionVal": [
{
"locale": "en",
"value": "International Masters"
},
{
"locale": "el",
"value": "---"
}
]
}
]
}
],
"Gender": [
{
"dropdownID": "Gender",
"data": [
{
"optionID": 0,
"optionVal": [
{
"locale": "en",
"value": "Male"
},
{
"locale": "el",
"value": "---"
}
]
},
{
"optionID": 1,
"optionVal": [
{
"locale": "en",
"value": "Female"
},
{
"locale": "el",
"value": "---"
}
]
},
{
"optionID": 2,
"optionVal": [
{
"locale": "en",
"value": "Intersex"
},
{
"locale": "el",
"value": "---"
}
]
}
]
}
],
"my-selection": [
{
"Name": "Andris",
"Surname": "Priede",
"Gender": "male",
"Date of birth": "11.05.1985",
"Place of birth": "Riga",
"phonenumber": "+37129999999",
"E-mail": "andris.priede@gmail.com",
"Course": "International Undergraduate",
"id": 1
}
]
}
index.js 0 → 100644
// server.js
const swaggerUi = require('swagger-ui-express');
const path = require('path');
const jsonServer = require('json-server');
const yaml = require('js-yaml');
const fs = require('fs');
const routes = require('./routes');
// const multer = require('multer');
const server = jsonServer.create();
const router = jsonServer.router(path.join(__dirname, 'db.json'));
const middlewares = jsonServer.defaults();
//const swaggerDocument = yaml.load(fs.readFileSync('./swagger-birthcertificate.yaml', 'utf8'));
server.get('/', (req, res) => {
res.redirect('/api-docs')
})
server.use(jsonServer.bodyParser);
server.post('/my-selection', (req, res) => {
let postData = req.body;
let databaseFile = "db.json";
let jsonData = fs.readFileSync(databaseFile);
let myObject = JSON.parse(jsonData);
let lastId = myObject["my-selection"].length ? myObject["my-selection"][myObject["my-selection"].length - 1].id : 0;
let newId = lastId + 1;
postData["id"] = newId;
myObject["my-selection"].push(postData);
let newData = JSON.stringify(myObject, null, 2);
//console.log(newData)
fs.writeFile(databaseFile, newData, err => {
if (err) throw err;
});
let outputTitle = 'Congratulations your application was received and we will notify you once we have made decision'; // set output text
res.status(201).json(outputTitle);
});
server.use(
'/api-docs',
swaggerUi.serve,
swaggerUi.setup(swaggerDocument)
);
server.use(middlewares);
//server.use(upload.any());
server.use(jsonServer.rewriter(routes));
server.use(router);
server.listen(3333, () => {
console.log('JSON Server is running')
});
This diff is collapsed.
{
"name": "mock-api-apply-to-university",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"js-yaml": "^4.1.0",
"json-server": "^0.17.0",
"multer": "^1.4.5-lts.1",
"swagger-ui": "^4.10.3",
"swagger-ui-dist": "^4.10.3",
"swagger-ui-express": "^4.3.0"
}
}
{
"/children": "/children"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment