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
5 changes: 4 additions & 1 deletion devvit.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
},
"server": {
"entry": "dist/server/index.cjs"
},
"triggers": {
"onAppInstall": "/internal/post-create"
}
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
"deploy": "npm run build:client && npm run build:server && devvit upload",
"dev": "concurrently -p \"[{name}]\" -n \"CLIENT,SERVER,DEVVIT\" -c \"blue,green,magenta\" \"npm run dev:client\" \"npm run dev:server\" \"npm run dev:devvit\" --restart-tries 2",
"dev:client": "cd src/client && vite build --watch",
"dev:devvit": "devvit playtest YOUR_SUBREDDIT_NAME",
"dev:devvit": "devvit playtest",
"dev:server": "cd src/server && vite build --watch",
"login": "devvit login",
"type-check": "tsc --build"
},
"dependencies": {
"@devvit/client": "0.11.18",
"@devvit/public-api": "0.11.18",
"@devvit/reddit": "^0.11.18",
"@devvit/redis": "0.11.18",
"@devvit/server": "0.11.18",
"devvit": "latest",
Expand Down
37 changes: 37 additions & 0 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
} from "../shared/types/api";
import { createServer, context, getServerPort } from "@devvit/server";
import { redis } from "@devvit/redis";
import { reddit } from "@devvit/reddit";
import { Devvit } from "@devvit/public-api";

const app = express();

Expand Down Expand Up @@ -92,6 +94,41 @@ router.post<
});
});


router.post("/internal/post-create", async (_req, res): Promise<void> => {
const { subredditName } = context;
if (!subredditName) {
res.status(400).json({
status: "error",
message: "subredditName is required",
});
return;
}
reddit.submitPost({
runAs: 'USER',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why user?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i could go either way, was thinking it'd be nice as the default in the templates.

realizing i'll need to add the permissions in devvit.json too. what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a default inside of our platform if we want it as a default, not the template. I'm also not sure if things like text fallback can be updated if it's posted as user. I know that was an issue last time I tried it.

userGeneratedContent: {
text: 'Hello there! This is a test post from the Test HW-1 app.',
},
subredditName: subredditName,
title: 'Test Post from Test HW-1',
preview: Devvit.createElement("blocks", {
height: "tall",
children: [
Devvit.createElement("vstack", {
height: "100%",
width: "100%",
backgroundColor: "#ffbf0b",
}),
],
}),
});

res.json({
status: "success",
message: `Post created in subreddit ${subredditName}`,
});
});

// Use router middleware
app.use(router);

Expand Down