serve public files

This commit is contained in:
Guillaume Dorce 2022-09-02 09:58:41 +02:00
parent f8466fb261
commit 6716937735
7 changed files with 9 additions and 9 deletions

View File

@ -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);
}

View File

@ -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) {

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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, () => {

View File

@ -3,7 +3,7 @@ export {};
declare global {
namespace Express {
export interface Request {
userId?: number;
userId: number;
}
}
}