Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,27 @@ COPY . /app/

WORKDIR /app

RUN chown -R node:node /app && npm i --package-lock

FROM node:16

COPY . /app/

WORKDIR /app

RUN npm i --package-lock

# Disable debug mode
ENV NODE_ENV=production

# Restrict CORS
EXPOSE 8080
CORS_ORIGIN="http://yourdomain.com"

# Add security headers
EXPOSE 8080
HEADER X-Content-Type-Options nosniff
HEADER X-XSS-Protection "1; mode=block"
HEADER Content-Security-Policy "default-src 'self'; script-src 'self'; img-src 'self'; style-src 'self'; font-src 'self';"

CMD [ "npm", "start" ]
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ var port = 8080;

var client = new Client({
user: "postgres",
password: "mysecretpassword",
password: process.env.PASSWORD, // Assuming PASSWORD is set in the environment
host: "localhost",
port: 5432,
database: "postgres",
})
});
client.connect()

var main = async () => {
Expand Down Expand Up @@ -43,7 +43,7 @@ var main = async () => {
try {
var user = await client.query(`select *
from users
where id = ${req.params.id}`)
where id = $1`, [req.params.id]);
res.send(user.rows[0]);
} catch (e) {
console.error(e.message)
Expand Down