Skip to content

Commit

Permalink
- update
Browse files Browse the repository at this point in the history
  • Loading branch information
aalfiann committed Nov 9, 2020
1 parent fdda671 commit f2bd137
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion models/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const mongooseHandler = require('../lib/mongoose_handler.js')
const contactSchema = {
user_id: {
type: Number,
required: [true, 'id is required'],
required: [true, 'user_id is required'],
trim: true,
unique: true
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fastify-fullstack-skeleton",
"version": "3.0.9",
"version": "3.0.10",
"description": "Just simple Fastify fullstack skeleton",
"main": "server.js",
"scripts": {
Expand Down
12 changes: 0 additions & 12 deletions routes/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,7 @@ async function dbRoute (server, options) {
})

server.get('/db/search-contact', { schema: schema.searchContact }, async (request, reply) => {
if (!request.query.q) {
return reply.code(200).send({
message: 'Required query parameter "q" with more than 2 chars!',
statusCode: 200
})
}
const search = decodeURIComponent(request.query.q).trim()
if (!search || search.length < 3) {
return reply.code(200).send({
message: 'Query search must more than 2 chars!',
statusCode: 200
})
}
mongooseHandler.connect().then(done => {
// Query find like for name and address only
Contact.find({
Expand Down
9 changes: 9 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ const App = async () => {
server.register(require('./routes/api.js'))
server.register(require('./routes/db.js'))
server.register(require('./routes/page.js'))

// Plugins

// Cors
server.register(require('fastify-cors'), {
origin: '*',
methods: 'GET, HEAD, PUT, PATCH, POST, DELETE, OPTIONS',
allowedHeaders: 'Content-Type, Authorization, X-Requested-With, Etag, X-Auth-Key'
})

// Template Engine
server.register(require('point-of-view'), {
engine: {
eta: require('eta')
Expand All @@ -50,6 +55,7 @@ const App = async () => {
}

})

// Set everything inside public directory is static file
server.register(require('fastify-static'), {
root: path.join(__dirname, 'public'),
Expand All @@ -58,6 +64,7 @@ const App = async () => {
immutable: true,
decorateReply: false
})

// Set maxage cache longer for all files inside assets directory
server.register(require('fastify-static'), {
root: path.join(__dirname, 'public', 'assets'),
Expand All @@ -66,6 +73,8 @@ const App = async () => {
immutable: true,
decorateReply: false
})

// Mailer
server.register(nodeMailer, config.nodeMailerTransport)

// Custom Not Found Handler
Expand Down

0 comments on commit f2bd137

Please sign in to comment.