Created
December 20, 2019 05:56
-
-
Save satyapendem/8be6026a9563ac52ceda36ea83182fbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fastify = require('fastify')({ logger: true }); | |
const authRouter = require('./router/authRouter'); | |
const router = require('./router/router'); | |
fastify.register(require('fastify-jwt'), { | |
secret: "test@&%%PUY", // use .env for this | |
}); | |
//cross-origin | |
fastify.register(require('fastify-cors'), { | |
origin: '*', | |
}); | |
/** | |
* Works as a body-parser for request body | |
*/ | |
fastify.addContentTypeParser('application/json', { parseAs: 'string' }, (req, body, done) => { | |
try { | |
const json = JSON.parse(body); | |
done(null, json); | |
} catch (err) { | |
err.statusCode = 400; | |
done(err, undefined); | |
} | |
}); | |
fastify.register(require('./middleware/auth_middleware')); | |
fastify.register(authRouter); | |
fastify.register(router); | |
/** | |
* starting the server | |
*/ | |
const start = async () => { | |
try { | |
await fastify.listen(8823,'0.0.0.0'); | |
} catch (error) { | |
fastify.log.error(error); | |
process.exit(1); | |
} | |
}; | |
start(); | |
module.exports = fastify; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment