Skip to content

Commit

Permalink
feat(docker): run api server in docker [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
bartholomej committed Nov 22, 2024
1 parent 2299176 commit a7d5eab
Show file tree
Hide file tree
Showing 4 changed files with 614 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use Node.js LTS image
FROM node:20-alpine

# Create app directory
WORKDIR /usr/src/app

# Copy package.json and yarn.lock
COPY package.json yarn.lock ./

# Install dependencies
RUN yarn install

# Copy the application code
COPY . .

# Expose the app's port
EXPOSE 3000

# Start the application
CMD ["yarn", "tsx", "server.ts"]
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@babel/preset-typescript": "^7.26.0",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.14.0",
"@types/express": "^5.0.0",
"@types/node": "^22.9.0",
"@typescript-eslint/eslint-plugin": "^8.13.0",
"@typescript-eslint/parser": "^8.13.0",
Expand All @@ -44,6 +45,7 @@
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"express": "^4.21.1",
"globals": "^15.12.0",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
Expand Down
52 changes: 52 additions & 0 deletions server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import express from 'express';
import { csfd } from './src';
import { CSFDFilmTypes } from './src/interfaces/global';

const app = express();
const port = process.env.PORT || 3000;

app.get('/movie/:id', async (req, res) => {
try {
const movie = await csfd.movie(+req.params.id);
res.json(movie);
} catch (error) {
res.status(500).json({ error: 'Failed to fetch movie data' });
}
});

app.get('/creator/:id', async (req, res) => {
try {
const result = await csfd.creator(+req.params.id);
res.json(result);
} catch (error) {
res.status(500).json({ error: 'Failed to fetch creator data: ' + error });
}
});

app.get('/search/:query', async (req, res) => {
try {
const result = await csfd.search(req.params.query);
res.json(result);
} catch (error) {
res.status(500).json({ error: 'Failed to fetch search data: ' + error });
}
});

app.get('/user-ratings/:id', async (req, res) => {
const { allPages, allPagesDelay, excludes, includesOnly } = req.query;
try {
const result = await csfd.userRatings(req.params.id, {
allPages: allPages === 'true',
allPagesDelay: allPagesDelay ? +allPagesDelay : undefined,
excludes: excludes ? (excludes as string).split(',') as CSFDFilmTypes[] : undefined,
includesOnly: includesOnly ? (includesOnly as string).split(',') as CSFDFilmTypes[] : undefined
});
res.json(result);
} catch (error) {
res.status(500).json({ error: 'Failed to fetch user-ratings data: ' + error });
}
});

app.listen(port, () => {
console.log(`API is running on http://localhost:${port}`);
});
Loading

0 comments on commit a7d5eab

Please sign in to comment.