Skip to content

Commit a7d5eab

Browse files
committed
feat(docker): run api server in docker [WIP]
1 parent 2299176 commit a7d5eab

File tree

4 files changed

+614
-1
lines changed

4 files changed

+614
-1
lines changed

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use Node.js LTS image
2+
FROM node:20-alpine
3+
4+
# Create app directory
5+
WORKDIR /usr/src/app
6+
7+
# Copy package.json and yarn.lock
8+
COPY package.json yarn.lock ./
9+
10+
# Install dependencies
11+
RUN yarn install
12+
13+
# Copy the application code
14+
COPY . .
15+
16+
# Expose the app's port
17+
EXPOSE 3000
18+
19+
# Start the application
20+
CMD ["yarn", "tsx", "server.ts"]

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@babel/preset-typescript": "^7.26.0",
3636
"@eslint/eslintrc": "^3.1.0",
3737
"@eslint/js": "^9.14.0",
38+
"@types/express": "^5.0.0",
3839
"@types/node": "^22.9.0",
3940
"@typescript-eslint/eslint-plugin": "^8.13.0",
4041
"@typescript-eslint/parser": "^8.13.0",
@@ -44,6 +45,7 @@
4445
"eslint-config-google": "^0.14.0",
4546
"eslint-config-prettier": "^9.1.0",
4647
"eslint-plugin-prettier": "^5.2.1",
48+
"express": "^4.21.1",
4749
"globals": "^15.12.0",
4850
"husky": "^9.1.6",
4951
"lint-staged": "^15.2.10",

server.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import express from 'express';
2+
import { csfd } from './src';
3+
import { CSFDFilmTypes } from './src/interfaces/global';
4+
5+
const app = express();
6+
const port = process.env.PORT || 3000;
7+
8+
app.get('/movie/:id', async (req, res) => {
9+
try {
10+
const movie = await csfd.movie(+req.params.id);
11+
res.json(movie);
12+
} catch (error) {
13+
res.status(500).json({ error: 'Failed to fetch movie data' });
14+
}
15+
});
16+
17+
app.get('/creator/:id', async (req, res) => {
18+
try {
19+
const result = await csfd.creator(+req.params.id);
20+
res.json(result);
21+
} catch (error) {
22+
res.status(500).json({ error: 'Failed to fetch creator data: ' + error });
23+
}
24+
});
25+
26+
app.get('/search/:query', async (req, res) => {
27+
try {
28+
const result = await csfd.search(req.params.query);
29+
res.json(result);
30+
} catch (error) {
31+
res.status(500).json({ error: 'Failed to fetch search data: ' + error });
32+
}
33+
});
34+
35+
app.get('/user-ratings/:id', async (req, res) => {
36+
const { allPages, allPagesDelay, excludes, includesOnly } = req.query;
37+
try {
38+
const result = await csfd.userRatings(req.params.id, {
39+
allPages: allPages === 'true',
40+
allPagesDelay: allPagesDelay ? +allPagesDelay : undefined,
41+
excludes: excludes ? (excludes as string).split(',') as CSFDFilmTypes[] : undefined,
42+
includesOnly: includesOnly ? (includesOnly as string).split(',') as CSFDFilmTypes[] : undefined
43+
});
44+
res.json(result);
45+
} catch (error) {
46+
res.status(500).json({ error: 'Failed to fetch user-ratings data: ' + error });
47+
}
48+
});
49+
50+
app.listen(port, () => {
51+
console.log(`API is running on http://localhost:${port}`);
52+
});

0 commit comments

Comments
 (0)