48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import express, { type Request, type Response } from 'express';
|
|
|
|
// import cors from 'cors';
|
|
import fileUpload from 'express-fileupload';
|
|
import {testDatabaseConnection} from './connection';
|
|
import path from 'path';
|
|
|
|
const app: express.Application = express();
|
|
|
|
// this is for dotenv
|
|
import { config } from 'dotenv';
|
|
config();
|
|
const port = process.env.PORT || 3011;
|
|
|
|
// Serve static files from the 'assets' directory
|
|
app.use(express.static(path.join(__dirname, 'assets')));
|
|
|
|
// Middleware for express-form-data
|
|
// app.use(formData.parse());
|
|
|
|
app.use(fileUpload({
|
|
createParentPath: true, // Creates the parent directory if it doesn't exist
|
|
}));
|
|
app.use(express.json());
|
|
app.use(express.urlencoded({ extended: true }));
|
|
|
|
// route
|
|
import firstRouter from './routes/first_router'; // route sebelum login
|
|
import guruRouter from './routes/guru_router'; // route guru
|
|
import siswaRouter from './routes/siswa_router'; // route siswa
|
|
|
|
testDatabaseConnection();
|
|
|
|
// routes
|
|
app.use('/', firstRouter);
|
|
app.use('/guru', guruRouter);
|
|
app.use('/siswa', siswaRouter);
|
|
|
|
// This should be the last route
|
|
app.use((req: Request, res: Response) => {
|
|
// res.send('Hello World!');
|
|
res.status(404).sendFile(path.join(__dirname, '/ui/first_pages/404.html'));
|
|
});
|
|
|
|
app.listen(port, () => {
|
|
console.log('Server is running on port ', port);
|
|
});
|