Skip to content

Commit

Permalink
fix: 🐛 update some missed unversioned /api paths (#674)
Browse files Browse the repository at this point in the history
fix: 🐛 Update some missed unversioned /api paths that should  be /api/2014
  • Loading branch information
fergcb authored Feb 23, 2025
1 parent a5f4fe9 commit 8bfe818
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ npm run dev
Request the image by navigating to an image URL in a browser, or via HTTP request:

```shell
curl http://localhost:3000/api/monsters/aboleth.png --output downloaded-aboleth.png
curl http://localhost:3000/api/2014/monsters/aboleth.png --output downloaded-aboleth.png
```

When interacting with the image you should see logs in the terminal where you started localstack. You can also use [localstack's webui](https://app.localstack.cloud/dashboard) to view the bucket and
Expand Down
18 changes: 9 additions & 9 deletions src/controllers/api/2014/classController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const show = async (req: Request, res: Response, next: NextFunction) =>
export const showLevelsForClass = async (req: Request, res: Response, next: NextFunction) => {
try {
const searchQueries: ShowLevelsForClassQuery = {
'class.url': '/api/classes/' + req.params.index,
'class.url': '/api/2014/classes/' + req.params.index,
$or: [{ subclass: null }],
};

Expand All @@ -51,7 +51,7 @@ export const showLevelForClass = async (req: Request, res: Response, next: NextF
return res.status(404).json({ error: 'Not found' });
}

const urlString = '/api/classes/' + req.params.index + '/levels/' + req.params.level;
const urlString = '/api/2014/classes/' + req.params.index + '/levels/' + req.params.level;

const data = await Level.findOne({ url: urlString });
if (!data) return next();
Expand All @@ -67,7 +67,7 @@ export const showMulticlassingForClass = async (
next: NextFunction
) => {
try {
const urlString = '/api/classes/' + req.params.index;
const urlString = '/api/2014/classes/' + req.params.index;

const data = await Class.findOne({ url: urlString });
return res.status(200).json(data?.multi_classing);
Expand All @@ -78,7 +78,7 @@ export const showMulticlassingForClass = async (

export const showSubclassesForClass = async (req: Request, res: Response, next: NextFunction) => {
try {
const urlString = '/api/classes/' + req.params.index;
const urlString = '/api/2014/classes/' + req.params.index;

const data = await Subclass.find({ 'class.url': urlString })
.select({ index: 1, name: 1, url: 1, _id: 0 })
Expand Down Expand Up @@ -124,7 +124,7 @@ export const showSpellcastingForClass = async (req: Request, res: Response, next

export const showSpellsForClass = async (req: Request, res: Response, next: NextFunction) => {
try {
const urlString = '/api/classes/' + req.params.index;
const urlString = '/api/2014/classes/' + req.params.index;

const data = await Spell.find({ 'classes.url': urlString })
.select({ index: 1, level: 1, name: 1, url: 1, _id: 0 })
Expand All @@ -145,7 +145,7 @@ export const showSpellsForClassAndLevel = async (
return res.status(404).json({ error: 'Not found' });
}

const urlString = '/api/classes/' + req.params.index;
const urlString = '/api/2014/classes/' + req.params.index;

const data = await Spell.find({
'classes.url': urlString,
Expand All @@ -161,7 +161,7 @@ export const showSpellsForClassAndLevel = async (

export const showFeaturesForClass = async (req: Request, res: Response, next: NextFunction) => {
try {
const urlString = '/api/classes/' + req.params.index;
const urlString = '/api/2014/classes/' + req.params.index;

const data = await Feature.find({
'class.url': urlString,
Expand All @@ -184,7 +184,7 @@ export const showFeaturesForClassAndLevel = async (
return res.status(404).json({ error: 'Not found' });
}

const urlString = '/api/classes/' + req.params.index;
const urlString = '/api/2014/classes/' + req.params.index;

const data = await Feature.find({
'class.url': urlString,
Expand All @@ -204,7 +204,7 @@ export const showProficienciesForClass = async (
next: NextFunction
) => {
try {
const urlString = '/api/classes/' + req.params.index;
const urlString = '/api/2014/classes/' + req.params.index;

const data = await Proficiency.find({ 'classes.url': urlString })
.select({ index: 1, name: 1, url: 1, _id: 0 })
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/api/2014/raceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const show = async (req: Request, res: Response, next: NextFunction) =>

export const showSubracesForRace = async (req: Request, res: Response, next: NextFunction) => {
try {
const urlString = '/api/races/' + req.params.index;
const urlString = '/api/2014/races/' + req.params.index;

const data = await Subrace.find({ 'race.url': urlString }).select({
index: 1,
Expand All @@ -32,7 +32,7 @@ export const showSubracesForRace = async (req: Request, res: Response, next: Nex

export const showTraitsForRace = async (req: Request, res: Response, next: NextFunction) => {
try {
const urlString = '/api/races/' + req.params.index;
const urlString = '/api/2014/races/' + req.params.index;

const data = await Trait.find({ 'races.url': urlString }).select({
index: 1,
Expand All @@ -48,7 +48,7 @@ export const showTraitsForRace = async (req: Request, res: Response, next: NextF

export const showProficienciesForRace = async (req: Request, res: Response, next: NextFunction) => {
try {
const urlString = '/api/races/' + req.params.index;
const urlString = '/api/2014/races/' + req.params.index;

const data = await Proficiency.find({ 'races.url': urlString })
.select({ index: 1, name: 1, url: 1, _id: 0 })
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/api/2014/subclassController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const show = async (req: Request, res: Response, next: NextFunction) =>

export const showLevelsForSubclass = async (req: Request, res: Response, next: NextFunction) => {
try {
const urlString = '/api/subclasses/' + req.params.index;
const urlString = '/api/2014/subclasses/' + req.params.index;

const data = await Level.find({ 'subclass.url': urlString }).sort({ level: 'asc' });
return res.status(200).json(data);
Expand All @@ -29,7 +29,7 @@ export const showLevelForSubclass = async (req: Request, res: Response, next: Ne
return res.status(404).json({ error: 'Not found' });
}

const urlString = '/api/subclasses/' + req.params.index + '/levels/' + req.params.level;
const urlString = '/api/2014/subclasses/' + req.params.index + '/levels/' + req.params.level;

const data = await Level.findOne({ url: urlString });
if (!data) return next();
Expand All @@ -41,7 +41,7 @@ export const showLevelForSubclass = async (req: Request, res: Response, next: Ne

export const showFeaturesForSubclass = async (req: Request, res: Response, next: NextFunction) => {
try {
const urlString = '/api/subclasses/' + req.params.index;
const urlString = '/api/2014/subclasses/' + req.params.index;

const data = await Feature.find({
'subclass.url': urlString,
Expand All @@ -64,7 +64,7 @@ export const showFeaturesForSubclassAndLevel = async (
return res.status(404).json({ error: 'Not found' });
}

const urlString = '/api/subclasses/' + req.params.index;
const urlString = '/api/2014/subclasses/' + req.params.index;

const data = await Feature.find({
level: parseInt(req.params.level),
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/api/2014/subraceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const show = async (req: Request, res: Response, next: NextFunction) =>

export const showTraitsForSubrace = async (req: Request, res: Response, next: NextFunction) => {
try {
const urlString = '/api/subraces/' + req.params.index;
const urlString = '/api/2014/subraces/' + req.params.index;
const data = await Trait.find({ 'subraces.url': urlString }).select({
index: 1,
name: 1,
Expand All @@ -34,7 +34,7 @@ export const showProficienciesForSubrace = async (
next: NextFunction
) => {
try {
const urlString = '/api/subraces/' + req.params.index;
const urlString = '/api/2014/subraces/' + req.params.index;

const data = await Proficiency.find({ 'races.url': urlString })
.select({ index: 1, name: 1, url: 1, _id: 0 })
Expand Down
4 changes: 2 additions & 2 deletions src/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h2>The 5th Edition Dungeons and Dragons API</h2>
<div class="interactive-section">
<h1>Try it now!</h1>
<div class="api-input">
<span class="api-prefix">https://www.dnd5eapi.co/api/</span>
<span class="api-prefix">https://www.dnd5eapi.co/api/2014/</span>
<input id="interactive" type="text" placeholder="spells/acid-arrow/" />
<button onclick="interactiveCall();return false;">
submit
Expand Down Expand Up @@ -148,4 +148,4 @@ <h1>Try it now!</h1>
</script>
</body>

</html>
</html>
10 changes: 5 additions & 5 deletions src/util/prewarmCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ const prewarmCache = async () => {
const toPrewarm: PrewarmData[] = [
{
Schema: MagicItem,
endpoint: '/api/magic-items',
endpoint: '/api/2014/magic-items',
},
{
Schema: Spell,
endpoint: '/api/spells',
endpoint: '/api/2014/spells',
},
{
Schema: Monster,
endpoint: '/api/monsters',
endpoint: '/api/2014/monsters',
},
{
Schema: Rule,
endpoint: '/api/rules',
endpoint: '/api/2014/rules',
},
{
Schema: RuleSection,
endpoint: '/api/rule-sections',
endpoint: '/api/2014/rule-sections',
},
];
for (const element of toPrewarm) {
Expand Down

0 comments on commit 8bfe818

Please sign in to comment.