Skip to content
Merged
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
2 changes: 1 addition & 1 deletion apps/backend/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/backend/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello via Bun!");
7 changes: 5 additions & 2 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{

"name": "backend",
"module": "index.ts",
"dependencies": {
Expand All @@ -22,15 +23,17 @@
"eslint-config-prettier": "^10.1.8",
"prettier": "^3.6.2",
"ts-node": "^10.9.2",
"typescript": "5.8.3",
"typescript": "^5.8.3",
"typescript-eslint": "^8.30.0"
},
"private": true,
"scripts": {
"dev": "bun run --watch src/index.ts",
"build": "bun build src/index.ts --outdir ./dist --target node",
"lint": "bun eslint src/**/*.ts",
"format": "bun prettier --write 'src/**/*.ts'"
"format": "bun prettier --write 'src/**/*.ts'",
"setup": "bun run scripts/setup.ts",
"clean": "bun run scripts/clean.ts"
},
"type": "module"
}
15 changes: 15 additions & 0 deletions apps/backend/scripts/clean.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { fileManager } from '../src/utils/fileManager';

async function main() {
const customPath = process.argv[2];

try {
await fileManager.cleanupProject(customPath);
console.log(' Cleanup completed successfully');
} catch (error) {
console.error(' Cleanup failed:', error instanceof Error ? error.message : error);
process.exit(1);
}
}

await main();
17 changes: 17 additions & 0 deletions apps/backend/scripts/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { fileManager } from '../src/utils/fileManager';

async function main() {
try {
const projectPath = await fileManager.setupProject();
console.log('Project created at:', projectPath);
console.log('\nTo clean up later, run:');
console.log('bun run clean');
console.log('or to clean a specific path:');
console.log('bun run clean -- /path/to/project');
} catch (error) {
console.error('Setup failed:', error instanceof Error ? error.message : error);
process.exit(1);
}
}

await main();
59 changes: 58 additions & 1 deletion apps/backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
import express from 'express';
import helmet from 'helmet';
import cors from 'cors';
import { setupProject, getSanitizedDirName, createRustProject } from './utils/fileManager';

const app = express();

// Security middleware
app.use(
helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
styleSrc: ["'self'", "'unsafe-inline'"],
scriptSrc: ["'self'"],
imgSrc: ["'self'", 'data:', 'https:'],
},
},
crossOriginEmbedderPolicy: false,
hsts: {
maxAge: 31536000,
includeSubDomains: true,
preload: true,
},
})
);

// CORS configuration
app.use(
cors({
origin: 'http://localhost:4200',
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization', 'Accept'],
optionsSuccessStatus: 200,
})
);

// Body parsing middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

// Routes
app.get('/', (_, res) =>
res.send('Hello from Backend!' + '<br>' + 'The best online soroban compiler is coming...')
);
Expand Down Expand Up @@ -45,4 +82,24 @@ app.post('/api/test-filemanager', async (req, res) => {
}
});

app.listen(3000, () => console.log('Server on http://localhost:3000'));
// Error handling middleware
app.use((err: Error, req: express.Request, res: express.Response, next: express.NextFunction) => {
res.status(500).json({
error: 'Internal Server Error',
message: process.env.NODE_ENV === 'development' ? err.message : 'Something went wrong',
});
});

// 404 handler
app.use((req, res) => {
res.status(404).json({
error: 'Not Found',
message: `Route ${req.originalUrl} not found`,
});
});

// Start server
app.listen(3000, () => {
console.log('Server on http://localhost:3000');
console.log('CORS restricted to http://localhost:4200');
});