mirror of
https://github.com/aleleba/run-app-from-cdn.git
synced 2025-07-05 09:48:11 -06:00
PR-220602: Adding first commit.
This commit is contained in:
17
src/app.ts
Normal file
17
src/app.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import express from 'express';
|
||||
import dotenv from 'dotenv';
|
||||
import { setRoutes } from './routes/index';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
setRoutes(app);
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Servidor corriendo en http://localhost:${PORT}`);
|
||||
});
|
14
src/controllers/index.ts
Normal file
14
src/controllers/index.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { Request, Response } from 'express';
|
||||
|
||||
export const getIndex = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const cdnUrl = process.env.CDN_URL;
|
||||
if (!cdnUrl) {
|
||||
res.status(500).send('CDN URL not configured');
|
||||
return;
|
||||
}
|
||||
res.redirect(cdnUrl);
|
||||
} catch (error) {
|
||||
res.status(500).send('Internal Server Error');
|
||||
}
|
||||
};
|
8
src/routes/index.ts
Normal file
8
src/routes/index.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { Application, Request, Response } from 'express';
|
||||
import { getIndex } from '../controllers/index';
|
||||
|
||||
export function setRoutes(app: Application) {
|
||||
app.get('/', (req: Request, res: Response) => {
|
||||
getIndex(req, res);
|
||||
});
|
||||
}
|
7
src/types/index.ts
Normal file
7
src/types/index.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export interface CustomRequest extends Express.Request {
|
||||
// Puedes agregar propiedades personalizadas aquí
|
||||
}
|
||||
|
||||
export interface CustomResponse extends Express.Response {
|
||||
// Puedes agregar propiedades personalizadas aquí
|
||||
}
|
Reference in New Issue
Block a user