-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (54 loc) · 1.8 KB
/
index.js
File metadata and controls
64 lines (54 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const express = require('express');
const bodyParser = require('body-parser');
require('dotenv').config({ path: '.env.local' });
const app = express();
// Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// CORS (for development - configure properly for production)
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
next();
});
// Routes
const artistProfileRoutes = require('./routes/artistProfile');
app.use('/api/artist', artistProfileRoutes);
// Default route
app.get('/', (req, res) => {
res.json({
message: 'Welcome to Strezless API 🎵',
version: '1.0.0',
endpoints: {
artist: {
createProfile: 'POST /api/artist/profile',
getProfile: 'GET /api/artist/profile/:id',
updateProfile: 'PUT /api/artist/profile/:id',
updateIdentifiers: 'PUT /api/artist/identifiers/:artistId',
search: 'GET /api/artist/search'
}
}
});
});
// Health check
app.get('/health', (req, res) => {
res.json({ status: 'healthy', timestamp: new Date().toISOString() });
});
// Error handling middleware
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).json({
success: false,
message: 'Something went wrong!',
error: process.env.NODE_ENV === 'development' ? err.message : undefined
});
});
// Set up the port
const PORT = process.env.PORT || 3000;
// Start the server
app.listen(PORT, () => {
console.log(`🎵 Strezless API running at http://localhost:${PORT}`);
console.log(`📊 Environment: ${process.env.NODE_ENV || 'development'}`);
});
module.exports = app;