Skip to content

Commit

Permalink
chore: display cors on prod same site
Browse files Browse the repository at this point in the history
  • Loading branch information
aseerkt committed Aug 9, 2024
1 parent da1cb9b commit d35bbf1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
15 changes: 3 additions & 12 deletions .github/workflows/ec2-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,15 @@ jobs:
runs-on: self-hosted
needs: build
steps:
- name: Download math result for job 1
- name: Download build files
uses: actions/download-artifact@v4
with:
name: mchat_build

- name: Move static files
run: |
sudo rm -rf /var/www/html/*
sudo mv web/dist/* /var/www/html/
sudo rm -rf web/dist
- name: Reload caddy service
run: |
sudo systemctl reload caddy
# - name: Set server env file
# run:
# cd server && cp .env.example .env
sudo mv web/dist server/
rm -rf server/src
- name: Restart application
run: pm2 restart mchat
Expand Down
4 changes: 1 addition & 3 deletions infra/ec2/Caddyfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
mchat.aseerkt.com {
root * /var/www/html
encode zstd gzip
file_server
reverse_proxy /api/* 127.0.0.1:5000
reverse_proxy * 127.0.0.1:5000
}
2 changes: 2 additions & 0 deletions infra/ec2/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ cp ./Caddyfile /etc/caddy/Caddyfile
./reload-caddy.sh

./docker-up.sh

# configure env file by hand
4 changes: 3 additions & 1 deletion server/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
PORT=5000
JWT_SECRET=
NODE_ENV=
ACCESS_TOKEN_SECRET=
REFRESH_TOKEN_SECRET=
DB_URL="postgresql://postgres:secret@localhost:5432/mchat"
REDIS_HOST=
REDIS_PORT=
Expand Down
10 changes: 8 additions & 2 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ const createApp = async () => {
app.use(
express.urlencoded({ extended: true }),
express.json(),
cors({ origin: config.corsOrigin, credentials: true }),
helmet(),
morgan(config.isProd ? 'combined' : 'dev'),
)

if (!config.isProd) {
app.use(cors({ origin: config.corsOrigin, credentials: true }))
}

app.use(cookieParser())

const server = createServer(app)
Expand All @@ -53,7 +57,9 @@ const createApp = async () => {
InterServerEvents,
SocketData
>(server, {
cors: { origin: config.corsOrigin, credentials: true },
cors: config.isProd
? undefined
: { origin: config.corsOrigin, credentials: true },
adapter: createAdapter(redisClient),
})

Expand Down

0 comments on commit d35bbf1

Please sign in to comment.