serve public files
This commit is contained in:
parent
f8466fb261
commit
6716937735
|
|
@ -4,8 +4,7 @@ import { Request, Response } from 'express';
|
|||
export default async (req: Request, res: Response) => {
|
||||
try {
|
||||
const id = parseInt(req.params.id);
|
||||
const userId = 1; // hardcoded for now, use userId from token
|
||||
const deletedPost = await deletePost(id, userId);
|
||||
const deletedPost = await deletePost(id, req.userId);
|
||||
if (deletedPost instanceof Error) {
|
||||
return res.status(403).send(deletedPost.message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { Request, Response } from 'express';
|
|||
export default async (req: Request, res: Response) => {
|
||||
try {
|
||||
req.body.id = parseInt(req.params.id);
|
||||
req.body.authorId = 1; // hardcoded for now, use userId from token
|
||||
req.body.authorId = req.userId;
|
||||
const post: Post = Post.parse(req.body);
|
||||
const editedPost: PrismaPost | null | Error = await editPost(post);
|
||||
if (editedPost === null) {
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ import { Request, Response } from 'express';
|
|||
export default async (req: Request, res: Response) => {
|
||||
try {
|
||||
const id = parseInt(req.params.id);
|
||||
const userId = 1; // hardcoded for now, use userId from token
|
||||
const likedPost = await likePost(id, userId);
|
||||
const likedPost = await likePost(id, req.userId);
|
||||
if (likedPost instanceof Error) {
|
||||
return res.status(403).send(likedPost.message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { Request, Response } from 'express';
|
|||
|
||||
export default async (req: Request, res: Response) => {
|
||||
try {
|
||||
req.body.authorId = 1; // hardcoded for now, use userId from token
|
||||
req.body.authorId = req.userId;
|
||||
const post: Post = Post.parse(req.body);
|
||||
const newPost: PrismaPost = await createPost(post);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ import { Request, Response } from 'express';
|
|||
export default async (req: Request, res: Response) => {
|
||||
try {
|
||||
const postId = parseInt(req.params.id);
|
||||
const userId = 1; // hardcoded for now, use userId from token
|
||||
const likedPost = await unlikePost(postId, userId);
|
||||
const likedPost = await unlikePost(postId, req.userId);
|
||||
if (likedPost instanceof Error) {
|
||||
return res.status(403).send(likedPost.message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import api from '@/api';
|
|||
import { config as envConfig } from 'dotenv';
|
||||
import { deleteExpiredTokens } from '@/controller/AuthController';
|
||||
import ms from 'ms';
|
||||
import path from 'path';
|
||||
|
||||
envConfig();
|
||||
|
||||
|
|
@ -40,6 +41,8 @@ app.use(cors());
|
|||
app.use(json({ limit: '50mb' }));
|
||||
app.use(urlencoded({ extended: true, limit: '50mb' }));
|
||||
|
||||
app.use(express.static(path.join(__dirname, '../public')));
|
||||
|
||||
app.use('/api', api);
|
||||
|
||||
app.listen(port, () => {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ export {};
|
|||
declare global {
|
||||
namespace Express {
|
||||
export interface Request {
|
||||
userId?: number;
|
||||
userId: number;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue