Skip to content

Commit b01db89

Browse files
committed
initialize
0 parents  commit b01db89

21 files changed

+1116
-0
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_size = 2
6+
indent_style = space
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.env.example

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
HOST=127.0.0.1
2+
PORT=3333
3+
NODE_ENV=development
4+
5+
APP_NAME=AdonisJs
6+
APP_URL=http://${HOST}:${PORT}
7+
8+
CACHE_VIEWS=false
9+
10+
APP_KEY=
11+
12+
DB_CONNECTION=sqlite
13+
DB_HOST=127.0.0.1
14+
DB_PORT=3306
15+
DB_USER=root
16+
DB_PASSWORD=
17+
DB_DATABASE=adonis
18+
19+
HASH_DRIVER=bcrypt

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Node modules
2+
node_modules
3+
package-lock.json
4+
5+
# Adonis directory for storing tmp files
6+
tmp
7+
8+
# Environment variables, never commit this file
9+
.env
10+
11+
# The development sqlite file
12+
database/development.sqlite

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Adonis API application
2+
3+
This is the boilerplate for creating an API server in AdonisJs, it comes pre-configured with.
4+
5+
1. Bodyparser
6+
2. Authentication
7+
3. CORS
8+
4. Lucid ORM
9+
5. Migrations and seeds
10+
11+
## Setup
12+
13+
Use the adonis command to install the blueprint
14+
15+
```bash
16+
adonis new yardstick --api-only
17+
```
18+
19+
or manually clone the repo and then run `npm install`.
20+
21+
22+
### Migrations
23+
24+
Run the following command to run startup migrations.
25+
26+
```js
27+
adonis migration:run
28+
```

ace

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict'
2+
3+
/*
4+
|--------------------------------------------------------------------------
5+
| Ace Commands
6+
|--------------------------------------------------------------------------
7+
|
8+
| The ace file is just a regular Javascript file but with no extension. You
9+
| can call `node ace` followed by the command name and it just works.
10+
|
11+
| Also you can use `adonis` followed by the command name, since the adonis
12+
| global proxy all the ace commands.
13+
|
14+
*/
15+
16+
const { Ignitor } = require('@adonisjs/ignitor')
17+
18+
new Ignitor(require('@adonisjs/fold'))
19+
.appRoot(__dirname)
20+
.fireAce()
21+
.catch(console.error)

app/Models/Token.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict'
2+
3+
/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
4+
const Model = use('Model')
5+
6+
class Token extends Model {
7+
}
8+
9+
module.exports = Token

app/Models/User.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict'
2+
3+
/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
4+
const Model = use('Model')
5+
6+
/** @type {import('@adonisjs/framework/src/Hash')} */
7+
const Hash = use('Hash')
8+
9+
class User extends Model {
10+
static boot () {
11+
super.boot()
12+
13+
/**
14+
* A hook to hash the user password before saving
15+
* it to the database.
16+
*/
17+
this.addHook('beforeSave', async (userInstance) => {
18+
if (userInstance.dirty.password) {
19+
userInstance.password = await Hash.make(userInstance.password)
20+
}
21+
})
22+
}
23+
24+
/**
25+
* A relationship on tokens is required for auth to
26+
* work. Since features like `refreshTokens` or
27+
* `rememberToken` will be saved inside the
28+
* tokens table.
29+
*
30+
* @method tokens
31+
*
32+
* @return {Object}
33+
*/
34+
tokens () {
35+
return this.hasMany('App/Models/Token')
36+
}
37+
}
38+
39+
module.exports = User

config/app.js

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
'use strict'
2+
3+
/** @type {import('@adonisjs/framework/src/Env')} */
4+
const Env = use('Env')
5+
6+
module.exports = {
7+
8+
/*
9+
|--------------------------------------------------------------------------
10+
| Application Name
11+
|--------------------------------------------------------------------------
12+
|
13+
| This value is the name of your application and can used when you
14+
| need to place the application's name in a email, view or
15+
| other location.
16+
|
17+
*/
18+
19+
name: Env.get('APP_NAME', 'AdonisJs'),
20+
21+
/*
22+
|--------------------------------------------------------------------------
23+
| App Key
24+
|--------------------------------------------------------------------------
25+
|
26+
| App key is a randomly generated 16 or 32 characters long string required
27+
| to encrypted cookies, sessions and other sensitive data.
28+
|
29+
*/
30+
appKey: Env.getOrFail('APP_KEY'),
31+
32+
http: {
33+
/*
34+
|--------------------------------------------------------------------------
35+
| Allow Method Spoofing
36+
|--------------------------------------------------------------------------
37+
|
38+
| Method spoofing allows to make requests by spoofing the http verb.
39+
| Which means you can make a GET request but instruct the server to
40+
| treat as a POST or PUT request. If you want this feature, set the
41+
| below value to true.
42+
|
43+
*/
44+
allowMethodSpoofing: true,
45+
46+
/*
47+
|--------------------------------------------------------------------------
48+
| Trust Proxy
49+
|--------------------------------------------------------------------------
50+
|
51+
| Trust proxy defines whether X-Forwaded-* headers should be trusted or not.
52+
| When your application is behind a proxy server like nginx, these values
53+
| are set automatically and should be trusted. Apart from setting it
54+
| to true or false Adonis supports handful or ways to allow proxy
55+
| values. Read documentation for that.
56+
|
57+
*/
58+
trustProxy: false,
59+
60+
/*
61+
|--------------------------------------------------------------------------
62+
| Subdomains
63+
|--------------------------------------------------------------------------
64+
|
65+
| Offset to be used for returning subdomains for a given request.For
66+
| majority of applications it will be 2, until you have nested
67+
| sudomains.
68+
| cheatsheet.adonisjs.com - offset - 2
69+
| virk.cheatsheet.adonisjs.com - offset - 3
70+
|
71+
*/
72+
subdomainOffset: 2,
73+
74+
/*
75+
|--------------------------------------------------------------------------
76+
| JSONP Callback
77+
|--------------------------------------------------------------------------
78+
|
79+
| Default jsonp callback to be used when callback query string is missing
80+
| in request url.
81+
|
82+
*/
83+
jsonpCallback: 'callback',
84+
85+
86+
/*
87+
|--------------------------------------------------------------------------
88+
| Etag
89+
|--------------------------------------------------------------------------
90+
|
91+
| Set etag on all HTTP response. In order to disable for selected routes,
92+
| you can call the `response.send` with an options object as follows.
93+
|
94+
| response.send('Hello', { ignoreEtag: true })
95+
|
96+
*/
97+
etag: false
98+
},
99+
100+
views: {
101+
/*
102+
|--------------------------------------------------------------------------
103+
| Cache Views
104+
|--------------------------------------------------------------------------
105+
|
106+
| Define whether or not to cache the compiled view. Set it to true in
107+
| production to optimize view loading time.
108+
|
109+
*/
110+
cache: Env.get('CACHE_VIEWS', true)
111+
},
112+
113+
static: {
114+
/*
115+
|--------------------------------------------------------------------------
116+
| Dot Files
117+
|--------------------------------------------------------------------------
118+
|
119+
| Define how to treat dot files when trying to server static resources.
120+
| By default it is set to ignore, which will pretend that dotfiles
121+
| does not exists.
122+
|
123+
| Can be one of the following
124+
| ignore, deny, allow
125+
|
126+
*/
127+
dotfiles: 'ignore',
128+
129+
/*
130+
|--------------------------------------------------------------------------
131+
| ETag
132+
|--------------------------------------------------------------------------
133+
|
134+
| Enable or disable etag generation
135+
|
136+
*/
137+
etag: true,
138+
139+
/*
140+
|--------------------------------------------------------------------------
141+
| Extensions
142+
|--------------------------------------------------------------------------
143+
|
144+
| Set file extension fallbacks. When set, if a file is not found, the given
145+
| extensions will be added to the file name and search for. The first
146+
| that exists will be served. Example: ['html', 'htm'].
147+
|
148+
*/
149+
extensions: false
150+
},
151+
152+
locales: {
153+
/*
154+
|--------------------------------------------------------------------------
155+
| Loader
156+
|--------------------------------------------------------------------------
157+
|
158+
| The loader to be used for fetching and updating locales. Below is the
159+
| list of available options.
160+
|
161+
| file, database
162+
|
163+
*/
164+
loader: 'file',
165+
166+
/*
167+
|--------------------------------------------------------------------------
168+
| Default Locale
169+
|--------------------------------------------------------------------------
170+
|
171+
| Default locale to be used by Antl provider. You can always switch drivers
172+
| in runtime or use the official Antl middleware to detect the driver
173+
| based on HTTP headers/query string.
174+
|
175+
*/
176+
locale: 'en'
177+
},
178+
179+
logger: {
180+
/*
181+
|--------------------------------------------------------------------------
182+
| Transport
183+
|--------------------------------------------------------------------------
184+
|
185+
| Transport to be used for logging messages. You can have multiple
186+
| transports using same driver.
187+
|
188+
| Available drivers are: `file` and `console`.
189+
|
190+
*/
191+
transport: 'console',
192+
193+
/*
194+
|--------------------------------------------------------------------------
195+
| Console Transport
196+
|--------------------------------------------------------------------------
197+
|
198+
| Using `console` driver for logging. This driver writes to `stdout`
199+
| and `stderr`
200+
|
201+
*/
202+
console: {
203+
driver: 'console',
204+
name: 'adonis-app',
205+
level: 'info'
206+
},
207+
208+
/*
209+
|--------------------------------------------------------------------------
210+
| File Transport
211+
|--------------------------------------------------------------------------
212+
|
213+
| File transport uses file driver and writes log messages for a given
214+
| file inside `tmp` directory for your app.
215+
|
216+
| For a different directory, set an absolute path for the filename.
217+
|
218+
*/
219+
file: {
220+
driver: 'file',
221+
name: 'adonis-app',
222+
filename: 'adonis.log',
223+
level: 'info'
224+
}
225+
},
226+
227+
/*
228+
|--------------------------------------------------------------------------
229+
| Generic Cookie Options
230+
|--------------------------------------------------------------------------
231+
|
232+
| The following cookie options are generic settings used by AdonisJs to create
233+
| cookies. However, some parts of the application like `sessions` can have
234+
| seperate settings for cookies inside `config/session.js`.
235+
|
236+
*/
237+
cookie: {
238+
httpOnly: true,
239+
sameSite: false,
240+
path: '/',
241+
maxAge: 7200
242+
}
243+
}

0 commit comments

Comments
 (0)