-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add basic fastify project with database connection. * add health & users/:id route. * add spec files & worfklow file for check.
- Loading branch information
1 parent
c67c9fc
commit 78ae647
Showing
13 changed files
with
8,326 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
POSTGRES_CONNECTION_STRING=postgres://postgres:1234@localhost/postgres | ||
PORT=3000 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
on: | ||
pull_request: | ||
branches: ['**'] | ||
types: [synchronize, opened, reopened, ready_for_review] | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
if: github.event.pull_request.draft == false # run this job only if the PR is not in a draft state | ||
strategy: | ||
matrix: | ||
node: [ '18' ] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
- run: npm i | ||
- name: test | ||
run: npm run test |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.env | ||
build | ||
node_modules/ | ||
.idea/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
# order-management | ||
A queue service to manage order using Fastify framework | ||
|
||
## Update .env file | ||
|
||
## run test | ||
```shell | ||
npm test | ||
``` | ||
|
||
## run server | ||
```shell | ||
npm start | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const fastifyPostgres = require('@fastify/postgres'); | ||
const dotenv = require('dotenv'); | ||
|
||
dotenv.config(); | ||
|
||
const setupDatabase = (fastify) => { | ||
fastify.register(fastifyPostgres, { | ||
connectionString: process.env.POSTGRES_CONNECTION_STRING, | ||
onConnect: async (client) => { | ||
fastify.log.info('Connected to PostgreSQL database'); | ||
}, | ||
}) | ||
.after(() => { | ||
// This block will run after the plugin is registered | ||
}) | ||
.addHook('onError', (request, reply, error, done) => { | ||
fastify.log.error(error.message); | ||
done(); | ||
}); | ||
}; | ||
|
||
module.exports = {setupDatabase} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const Fastify = require('fastify'); | ||
const { setupDatabase } = require('./config/db.js'); | ||
const { userRoutes } = require('./routes/users.js'); | ||
|
||
const fastify = Fastify({ | ||
logger: true, | ||
}); | ||
|
||
setupDatabase(fastify); | ||
userRoutes(fastify); | ||
|
||
fastify.get('/health', async (request, reply) => { | ||
reply.type('application/json').code(200); | ||
return { status: 'ok', uptime: process.uptime() }; | ||
}); | ||
|
||
fastify.listen({ port: process.env.PORT }, (err, address) => { | ||
if (err) { | ||
fastify.log.error(err); | ||
process.exit(1); | ||
} | ||
fastify.log.info(`Server listening on ${address}`); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
// preset: 'ts-jest', // enable if want to use typescript | ||
testEnvironment: 'node', | ||
testMatch: ['**/__tests__/**/*.js', '**/?(*.)+(spec|test).js'], | ||
moduleFileExtensions: ['js'], | ||
globals: { | ||
// 'ts-jest': { | ||
// tsconfig: 'path/to/your/tsconfig.json', // Specify your TypeScript configuration file | ||
// }, | ||
}, | ||
}; |
Oops, something went wrong.