Skip to content
Open
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
62 changes: 37 additions & 25 deletions backend/app.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
import 'dotenv/config'
import express from 'express'
import cors from 'cors'
import ipfsRoutes from './src/routes/ipfs.js'
import nftRoutes from './src/routes/nfts.js'
import 'dotenv/config';
import express from 'express';
import cors from 'cors';
import { graphqlHTTP } from 'express-graphql';
import { schema } from './src/graphql/schema.js'; // Import GraphQL schema
import { graphqlUploadExpress } from 'graphql-upload';

const app = express()
const port = process.env.PORT || 3000
const app = express();
const port = process.env.PORT || 3000;

app.use(express.json())
// Middleware to parse JSON
app.use(express.json());

// Allow all origins for now to simplify the frontend setup
// Enable file uploads for GraphQL
app.use(graphqlUploadExpress());

// Allow all origins for now to simplify frontend setup
app.use(
cors({
origin: '*',
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
methods: ['GET', 'POST', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization'],

})
)
);

app.use('/ipfs', ipfsRoutes)
app.use('/nfts', nftRoutes)
// Health check endpoint
app.get('/health', (req, res) => {
res.status(200).json({ status: 'ok' });
});

// Error handling middleware to ensure CORS headers are sent even on errors
// Set up the GraphQL server
app.use(
'/graphql',
graphqlHTTP({
schema, // GraphQL schema imported from the project
graphiql: process.env.NODE_ENV !== 'production', // Enable GraphiQL in development
})
);

// Error handling middleware to ensure consistent error responses
app.use((err, req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.status(err.status || 500).json({ error: err.message })
})
// Basic health check endpoint
app.get('/health', (req, res) => {
res.status(200).json({ status: 'ok' })
})
res.header('Access-Control-Allow-Origin', '*');
res.status(err.status || 500).json({ error: err.message });
});

// Start the server
app.listen(port, () => {
console.log(`Server is running on port ${port}`)
})
console.log(`GraphQL server is running on http://localhost:${port}/graphql`);
});

export default app
export default app;
195 changes: 191 additions & 4 deletions backend/package-lock.json

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

4 changes: 3 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"dotenv": "^16.4.7",
"ethers": "^6.13.4",
"express": "^4.21.1",
"express-graphql": "^0.12.0",
"graphql-upload": "^11.0.0",
"multer": "^1.4.5-lts.1",
"nodemon": "^3.1.7",
"pako": "^2.1.0",
Expand Down
Loading
Loading