Skip to content

Commit

Permalink
feat: use https for backend and add test cert
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlc03 committed Aug 28, 2024
1 parent 8bec6e5 commit fefce7f
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 6 deletions.
19 changes: 19 additions & 0 deletions packages/backend/cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIDDDCCAfQCCQCdGYDNX5c3CTANBgkqhkiG9w0BAQsFADBIMRMwEQYDVQQKDApI
YWNraW5nUFNFMRMwEQYDVQQDDApoYWNraW5ncHNlMRwwGgYJKoZIhvcNAQkBFg1h
ZG1pbkBwc2UuZGV2MB4XDTI0MDgyODEzMTcwMloXDTI1MDgyODEzMTcwMlowSDET
MBEGA1UECgwKSGFja2luZ1BTRTETMBEGA1UEAwwKaGFja2luZ3BzZTEcMBoGCSqG
SIb3DQEJARYNYWRtaW5AcHNlLmRldjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC
AQoCggEBALXbdoVtb/XxjBUYK9Uj5FSTNbUOXnsdjBwTCGWWvnCqwIoGAQIybY5K
ZTj7x+mbE0el3444s7Qo5yX8BQwFjKoLVHuVjZde0MTD3zVoWur+bnAgkWhTOi7o
Hsb2znaRLuzJtyIKBWZM56zB0xbbFWADrQCjxSkh4GKCL2zVofRGOU2vP7n1n3nZ
thhrPDfLf0bt9RmuopZMD+13s/DNJt1SPj/RJT2KU91cfLT/8e7lzzXpTJ1XUHRm
7e0C8hjlxUUeUWSxMkBQHoRrpxU+LRRhbFTFE6KOnlVQJo6JkOaaMOuxwZu0dZLO
QVKwHbsi87uRMloTZw+zxubTzgiSB2kCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEA
EZUTjI3AMyll0amgZIVx35OVLpSADHhG3NYGiqyVEFXSTEg0Crlc3DPIc8EzZqSX
DelIz20G/A4kzM8Edep6ngMkaYw7K9O96uu9JFnEIUCWlqErWFungSaQ9D+tWu5/
3UwiDwnnDMgSwrwoYmB1Bcgv59Fjq21tOotcu9ZyOR01d4p5prF9mLEPofPUpnmi
Y3TY1j/L0dcn11GUrRJl7uM/Xm4O06P6+I20Mo5FOnaLelv2tjwObv5W6Tj4wre4
cCihW9f9SYN6txFNfXm5E8H3TlL04DonBDqrfhX/5PF+asfKDZFpY4ZiccbfTHO9
hGYPi2ACDil9nR7Xamnw1A==
-----END CERTIFICATE-----
27 changes: 27 additions & 0 deletions packages/backend/key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAtdt2hW1v9fGMFRgr1SPkVJM1tQ5eex2MHBMIZZa+cKrAigYB
AjJtjkplOPvH6ZsTR6XfjjiztCjnJfwFDAWMqgtUe5WNl17QxMPfNWha6v5ucCCR
aFM6LugexvbOdpEu7Mm3IgoFZkznrMHTFtsVYAOtAKPFKSHgYoIvbNWh9EY5Ta8/
ufWfedm2GGs8N8t/Ru31Ga6ilkwP7Xez8M0m3VI+P9ElPYpT3Vx8tP/x7uXPNelM
nVdQdGbt7QLyGOXFRR5RZLEyQFAehGunFT4tFGFsVMUToo6eVVAmjomQ5pow67HB
m7R1ks5BUrAduyLzu5EyWhNnD7PG5tPOCJIHaQIDAQABAoIBAF18Vi89FOMfqt1l
MZM+AjCgBGnw2wz7IX2FIznmBjww6w2JDJeuiLcu814ZwKkMORsJ4CRiba7doAXc
ylNlvuvjKyjktobsDPI5ptLztFk9NlSZyWYR8sUOOlQZqAU3mSHMiEINWL1AJ5Cd
iwAi25giC5talQ4SBiFdvzd5kunZGcmQv8jnIs3eA6PbuNK7O+JrqXVmtd8hCOyQ
G8zOL5qEh+gSrUYz+aU5hB5H7LdmWnXwqfM3zSQ3Db+M78dIgMgd932Miuryk7yI
NUf4rnSIPjWHd716/9baSi41NmhzjCpZXwcTBeSdqRn1dcS2tND1KG1x4pFPfbz3
kTlonqECgYEA3iC6pVUvmzS/CtYAvxKiH73sbrTqmaNvsbMFPPJVYBLf1m2BXtNw
bmG7lUidB970oj2fNDZO6KcTcdf7psm0B0QQtgINIj5MJG0Cmkw/h2VjL9xSLkSm
zaNanx/unlm0Tq5CGgdx7FZ5yDyrKZm++o4kQF64WjWySvcz42U9jD0CgYEA0Zat
/FvQs+Ih7+RNq19Gp2QcMoLa9UjTVyY98JycrDSJ8W3l5lpJUDxG6Pmdicq9gW9K
qJDXvZ8f48y6tFY6grbiW7JdubiSBY6amEfVGCQdM+5p1CQWy6aXKRz/+ZrCIoKx
tQpnbZBf+sSp2O0AY3CsmLkXucYJNi0xz13Rfp0CgYBcOIhlJgXa0T5TuF+c9JZ8
yTRFDjWsTc+Mnj+Zex75AT0PYG1quiwel9LyerA/WVCFn0HewoFmVB9dj4c6StnE
fnzVo+piAi1Inj2LZAaoJu7UKwuvi+8Yxy5TjEVcVu/mDrEA74Bb19c9y/pgDiXd
DnB8jRbK1SpNt25ChYDVHQKBgQC4sFYbFnF/wlpzgbRrumaRZSdv313BXe5WUq2s
VOW+3gFcjaJUbeVC3gsCi8wmO1DpOUAJ8LEcOJeqbqNr/LxMqYookbID0cBjQzm5
zTrbrh9JvuLk/PRVezSjFxn+Q0CllpOwXD2uD9Z0LU8aiCaaehSt9BUTMI63ffXx
rNPKBQKBgEYlIIyjnfDvCGs54ypKTEPtR0LgD1MjZ+av2b2REtNFfhL8a6sZt1Hl
6QzT8cx0oCEHtN/vCLuEqDn+QKOlwU5bwY/FDO1nryyXDatzzMhoj8k2zzWJJVFJ
ehY6/iF0mIwCfW6dmx8vt3P5uG261pBIJZyLGhFwCEeM9ww/lMI9
-----END RSA PRIVATE KEY-----
10 changes: 8 additions & 2 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import express from 'express'
import bodyParser from 'body-parser'
import cors from 'cors'
import https from 'https'
import fs from 'fs'

import { sendOtp, verifyOtp } from './otp'
import { getDb, initDb } from './db'
Expand Down Expand Up @@ -113,8 +115,12 @@ app.post('/verify-otp', async (req, res) => {

// init db then start listening service
initDb().then(() => {
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`)
const httpsOptions = {
cert: fs.readFileSync('./cert.pem'),
key: fs.readFileSync('./key.pem')
}
https.createServer(httpsOptions, app).listen(port, () => {
console.log(`Server is running on https://localhost:${port}`)
})}).catch((err: any) => {
console.error('Failed to initialize database', err)
})
2 changes: 2 additions & 0 deletions packages/interface/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,5 @@ NEXT_PUBLIC_TALLY_URL=https://upblxu2duoxmkobt.public.blob.vercel-storage.com
NEXT_PUBLIC_POLL_MODE="non-qv"

NEXT_PUBLIC_ROUND_LOGO="round-logo.png"

NEXT_PUBLIC_BACKEND_URL="https://localhost:3001"
1 change: 1 addition & 0 deletions packages/interface/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const config: Config = {
pollMode: process.env.NEXT_PUBLIC_POLL_MODE ?? "non-qv",
roundLogo: process.env.NEXT_PUBLIC_ROUND_LOGO,
semaphoreSubgraphUrl: process.env.NEXT_PUBLIC_SEMAPHORE_SUBGRAPH,
backendUrl: process.env.NEXT_PUBLIC_BACKEND_URL!,
};

export const theme = {
Expand Down
4 changes: 4 additions & 0 deletions packages/interface/src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ module.exports = createEnv({
NEXT_PUBLIC_ROUND_LOGO: z.string().optional(),

NEXT_PUBLIC_SEMAPHORE_SUBGRAPH: z.string().url().optional(),

NEXT_PUBLIC_BACKEND_URL: z.string().url().optional(),
},

/**
Expand Down Expand Up @@ -109,6 +111,8 @@ module.exports = createEnv({
NEXT_PUBLIC_ROUND_LOGO: process.env.NEXT_PUBLIC_ROUND_LOGO,

NEXT_PUBLIC_SEMAPHORE_SUBGRAPH: process.env.NEXT_PUBLIC_SEMAPHORE_SUBGRAPH,

NEXT_PUBLIC_BACKEND_URL: process.env.NEXT_PUBLIC_BACKEND_URL,
},
/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially
Expand Down
6 changes: 2 additions & 4 deletions packages/interface/src/pages/signup/registerEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ const RegisterEmail = (): JSX.Element => {
const [emailField, setEmail] = useState<EmailField>();

const registerEmail = async (emailField: EmailField) => {
const url = "http://localhost:3001/send-otp";
try {
const response = await fetch(url, {
const response = await fetch(config.backendUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -65,8 +64,7 @@ const RegisterEmail = (): JSX.Element => {
const { otp: otp } = otpField;

try {
const url = "http://localhost:3001/verify-otp";
const response = await fetch(url, {
const response = await fetch(config.backendUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
1 change: 1 addition & 0 deletions packages/interface/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,5 @@ export type Config = {
pollMode: string;
roundLogo: string | undefined;
semaphoreSubgraphUrl: string | undefined;
backendUrl: string;
};

0 comments on commit fefce7f

Please sign in to comment.