Merge stable version before large change #16
@ -1,26 +1,8 @@
|
|||||||
pipeline:
|
pipeline:
|
||||||
build-frontend:
|
publish-dev:
|
||||||
image: node:16
|
image: node:18
|
||||||
commands:
|
when:
|
||||||
- cd frontend
|
branch: dev
|
||||||
- npm i
|
|
||||||
- npm run generate
|
|
||||||
publish-frontend:
|
|
||||||
image: node:16
|
|
||||||
secrets:
|
|
||||||
- meli_api_token
|
|
||||||
commands:
|
|
||||||
- cd frontend
|
|
||||||
- npx -p "@getmeli/cli" meli upload .output/public --url https://meli.xeovalyte.dev --site 1e43e574-3eea-4e90-8c52-8a9bcab54f3a --token $$MELI_API_TOKEN --branch "main"
|
|
||||||
|
|
||||||
build-backend:
|
|
||||||
image: node:16
|
|
||||||
commands:
|
|
||||||
- cd backend
|
|
||||||
- npm i
|
|
||||||
|
|
||||||
publish-backend:
|
|
||||||
image: plugins/docker
|
|
||||||
secrets:
|
secrets:
|
||||||
- docker_password
|
- docker_password
|
||||||
settings:
|
settings:
|
||||||
@ -31,5 +13,3 @@ pipeline:
|
|||||||
tags:
|
tags:
|
||||||
- latest
|
- latest
|
||||||
registry: gitea.xeovalyte.dev
|
registry: gitea.xeovalyte.dev
|
||||||
|
|
||||||
|
|
11
Dockerfile
11
Dockerfile
@ -1,9 +1,12 @@
|
|||||||
FROM node:16
|
FROM node:18
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
COPY ./backend .
|
COPY ./frontend .
|
||||||
|
|
||||||
EXPOSE 7289
|
RUN npm install
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
CMD [ "node", "index.js" ]
|
EXPOSE 3000
|
||||||
|
|
||||||
|
CMD [ "node", ".output/server/index.mjs" ]
|
||||||
|
1
backend/.gitignore
vendored
1
backend/.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
node_modules
|
|
@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "service_account",
|
|
||||||
"project_id": "wrbapp",
|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3lN76cn1WChPVLquN1hVLG2PCfDTEU91z6bRMRmm0n1oHfi9V98rsZUcauyuO5H\nF1JYg0K5ZSLjkCrITlPVovpJAViDluWB5WawYIOdY63GBQn6tm4HmEn/fFz0U8pw\nSLEvZl1WbQKBgQCv+SzwhmB1ykId/8IGy39FDWKG0O0TFj6xOqAPvOAdTFx9Yh5Q\nJBOxx8gzrNSKW6bdW7dJMyLfA2Dg2gb96BXIA3z8P/Z2QMh9YZ04pY4pFyqWcJ40\nlX7ddqVbTeTmXM+vWB2ztNHxPLKW1ROdPqS8vSSsgppgiRr6RdtzRVTeIQKBgErd\nHrRHVK2gHolus5U5KSu3Qbg8mEYVKTQT7DptpgI6/q/rTdn0ckW8Opn5FXbqn18u\nVnJ1/gTX8VHm64fn08HxwpcNe2aHs07Vtpj/VKt8on4PQ7VpFLsuN48ALGTdOO3N\nvzA3i9w52dyTlcGyy4woDAISSEc0f1aTPIoxojJtAoGAFn7IuYlO+7mludy/LaiN\ndfz4VbXJglSIqSH6JNy2OnHJSK43bQV2MPJ9FVxN1WKHixdxTcrEdLWMvtlymHJq\ne90seug41Op+nT3e3HdhIf1HeVAFr5vxNbFABgpdkVDJs8lnVJP13D0mEjF5CRUS\nLUFh+r1bedz4f1R2s8ODhWQ=\n-----END PRIVATE KEY-----\n",
|
|
||||||
"client_email": "firebase-adminsdk-iqgyy@wrbapp.iam.gserviceaccount.com",
|
|
||||||
"client_id": "101347063281519043654",
|
|
||||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
|
||||||
"token_uri": "https://oauth2.googleapis.com/token",
|
|
||||||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
|
||||||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-iqgyy%40wrbapp.iam.gserviceaccount.com"
|
|
||||||
}
|
|
179
backend/index.js
179
backend/index.js
@ -1,179 +0,0 @@
|
|||||||
const express = require('express');
|
|
||||||
const cors = require('cors');
|
|
||||||
const { initializeApp, applicationDefault, cert } = require('firebase-admin/app');
|
|
||||||
const { getFirestore, Timestamp, FieldValue } = require('firebase-admin/firestore');
|
|
||||||
const { getMessaging } = require('firebase-admin/messaging')
|
|
||||||
const { getAuth } = require('firebase-admin/auth')
|
|
||||||
|
|
||||||
const serviceAccount = require('./firebase.json');
|
|
||||||
|
|
||||||
initializeApp({
|
|
||||||
credential: cert(serviceAccount)
|
|
||||||
});
|
|
||||||
|
|
||||||
const db = getFirestore();
|
|
||||||
|
|
||||||
const app = express();
|
|
||||||
|
|
||||||
app.use(express.json());
|
|
||||||
app.use(cors({
|
|
||||||
origin: '*',
|
|
||||||
}));
|
|
||||||
|
|
||||||
app.listen(7289, () => console.log('API is online!'));
|
|
||||||
|
|
||||||
app.get('/', (req, res) => {
|
|
||||||
res.status(200).send({
|
|
||||||
status: 'success',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
app.post('/checkrelatiecode', async (req, res) => {
|
|
||||||
const { relatiecode, email } = req.body;
|
|
||||||
|
|
||||||
if (!relatiecode) return res.status(400).send({ code: 'no-relatiecode'})
|
|
||||||
if (!email) return res.status(400).send({ code: 'no-email'})
|
|
||||||
|
|
||||||
try {
|
|
||||||
const docRef = db.collection('ledenlijst').doc(relatiecode);
|
|
||||||
const doc = await docRef.get();
|
|
||||||
|
|
||||||
if (!doc.exists) return res.status(400).send({ code: 'incorrect'})
|
|
||||||
|
|
||||||
const data = doc.data()
|
|
||||||
|
|
||||||
if (data.email[0] === email || data.email[1] === email) {
|
|
||||||
return res.status(200).send({ code: 'correct'})
|
|
||||||
} else {
|
|
||||||
return res.status(400).send({ code: 'incorrect'})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
return res.status(500).send({ code: 'error', error: e })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
app.post('/getrelatiecodes', async (req, res) => {
|
|
||||||
const { email } = req.body;
|
|
||||||
|
|
||||||
if (!email) return res.status(400).send({ code: 'no-email'})
|
|
||||||
|
|
||||||
try {
|
|
||||||
const ledenlijstRef = db.collection('ledenlijst')
|
|
||||||
|
|
||||||
const snapshot = await ledenlijstRef.where("email", "array-contains", email).get()
|
|
||||||
|
|
||||||
if (snapshot.empty) {
|
|
||||||
res.status(400).send({ code: 'no-relatiecodes'})
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let relatiecodes = [];
|
|
||||||
let persons = [];
|
|
||||||
|
|
||||||
snapshot.forEach(doc => {
|
|
||||||
relatiecodes.push(doc.id)
|
|
||||||
const data = doc.data()
|
|
||||||
persons.push({ fullName: data.fullName, relatiecode: doc.id })
|
|
||||||
});
|
|
||||||
|
|
||||||
res.status(200).send({ code: 'success', relatiecodes: relatiecodes, persons: persons })
|
|
||||||
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
return res.status(500).send({ code: 'error', error: e })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
app.post('/subscribetotopic', async (req, res) => {
|
|
||||||
const { topic, registrationToken } = req.body;
|
|
||||||
|
|
||||||
if (!topic) return res.status(400).send({ code: 'no-topic'})
|
|
||||||
if (!registrationToken) return res.status(400).send({ code: 'no-registrationToken'})
|
|
||||||
|
|
||||||
try {
|
|
||||||
getMessaging().subscribeToTopic([registrationToken], topic)
|
|
||||||
.then((response) => {
|
|
||||||
console.log('Successfully subscribed to topic:', response);
|
|
||||||
|
|
||||||
res.status(200).send({ code: 'success' })
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log('Error subscribing to topic:', error);
|
|
||||||
|
|
||||||
return res.status(500).send({ code: 'error', error: error })
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
return res.status(500).send({ code: 'error', error: e })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
app.post('/sendmessage', async (req, res) => {
|
|
||||||
const { title, body, token } = req.body;
|
|
||||||
|
|
||||||
if (!title) return res.status(400).send({ code: 'no-topic'})
|
|
||||||
if (!body) return res.status(400).send({ code: 'no-registrationToken'})
|
|
||||||
if (!token) return res.status(400).send({ code: 'no-token'})
|
|
||||||
|
|
||||||
try {
|
|
||||||
getAuth()
|
|
||||||
.verifyIdToken(token)
|
|
||||||
.then(async (decodedToken) => {
|
|
||||||
const uid = decodedToken.uid;
|
|
||||||
|
|
||||||
const docRef = db.collection('users').doc(uid);
|
|
||||||
const doc = await docRef.get();
|
|
||||||
|
|
||||||
if (!doc.exists) return res.status(400).send({ code: 'not-found'})
|
|
||||||
|
|
||||||
const data = doc.data()
|
|
||||||
|
|
||||||
if (!data.sendNews) return res.status(400).send({ code: 'no-permissions'})
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
notification: {
|
|
||||||
title: title,
|
|
||||||
body: body,
|
|
||||||
icon: 'https://wrbapp.xeovalyte.com/ios/256.png',
|
|
||||||
},
|
|
||||||
topic: 'all',
|
|
||||||
apns: {
|
|
||||||
payload: {
|
|
||||||
aps: {
|
|
||||||
sound: 'default'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
getMessaging().send(message)
|
|
||||||
.then((response) => {
|
|
||||||
// Response is a message ID string.
|
|
||||||
console.log('Successfully sent message:', response);
|
|
||||||
|
|
||||||
res.status(200).send({ code: 'success', response: response })
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log('Error sending message:', error);
|
|
||||||
|
|
||||||
return res.status(500).send({ code: 'error', error: error })
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log(error)
|
|
||||||
|
|
||||||
return res.status(500).send({ code: 'error', error: error })
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
return res.status(500).send({ code: 'error', error: e })
|
|
||||||
}
|
|
||||||
})
|
|
Binary file not shown.
4036
backend/package-lock.json
generated
4036
backend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "backend",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"keywords": [],
|
|
||||||
"author": "",
|
|
||||||
"license": "ISC",
|
|
||||||
"dependencies": {
|
|
||||||
"cors": "^2.8.5",
|
|
||||||
"express": "^4.18.1",
|
|
||||||
"firebase-admin": "^11.0.1"
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user