parent
							
								
									0dd0ac74e1
								
							
						
					
					
						commit
						e9b9f01101
					
				
				 2 changed files with 21 additions and 13 deletions
			
			
		@ -1,14 +1,23 @@ | 
				
			|||||||
const express = require('express') | 
					const fastify = require('fastify')() | 
				
			||||||
const cors = require('cors') | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
const app = express() | 
					fastify.register(require('fastify-cors')) | 
				
			||||||
 | 
					 | 
				
			||||||
app.use(cors()) | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
const posts = require('./routes/api/posts') | 
					const posts = require('./routes/api/posts') | 
				
			||||||
 | 
					
 | 
				
			||||||
app.use('/posts', posts) | 
					// Assuming they are all get requests
 | 
				
			||||||
 | 
					for (let [route, resolver] of posts.entries()) { | 
				
			||||||
 | 
					  fastify.get('/posts' + route, resolver) | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
const port = process.env.PORT || 5000 | 
					const port = process.env.PORT || 5000 | 
				
			||||||
 | 
					
 | 
				
			||||||
app.listen(port, () => console.log(`Server started on port ${port}`)) | 
					const start = async () => { | 
				
			||||||
 | 
					  try { | 
				
			||||||
 | 
					    await fastify.listen(port) | 
				
			||||||
 | 
					    console.log(`Launched on port ${port} 🚀`) | 
				
			||||||
 | 
					  } catch (err) { | 
				
			||||||
 | 
					    fastify.log.error(err) | 
				
			||||||
 | 
					    process.exit(1) | 
				
			||||||
 | 
					  } | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					start() | 
				
			||||||
 | 
				
			|||||||
					Loading…
					
					
				
		Reference in new issue