-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docker): run api server in docker [WIP]
- Loading branch information
1 parent
2299176
commit a7d5eab
Showing
4 changed files
with
614 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
}); |
Oops, something went wrong.