Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kulakowka/strapi-frontend-example
Express.js server which works with strapi as backend
https://github.com/kulakowka/strapi-frontend-example
Last synced: 2 days ago
JSON representation
Express.js server which works with strapi as backend
- Host: GitHub
- URL: https://github.com/kulakowka/strapi-frontend-example
- Owner: kulakowka
- Created: 2016-01-31T20:37:34.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-01T23:44:09.000Z (almost 9 years ago)
- Last Synced: 2024-10-17T07:37:14.381Z (27 days ago)
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# strapi-frontend-example
- load data from REST api which gives Strapi application
- user login, register, logout. user stored in session.```javascript
// routes/auth.js
'use strict'
const express = require('express')
const apiRequest = require('../utils/api')let router = express.Router()
// GET /auth/login
router.get('/login', (req, res, next) => {
res.render('auth/login', {title: 'Sign in'})
})// POST /auth/local
router.post('/login', (req, res, next) => {
apiRequest
.post('/auth/local', {form: req.body}, (err, response, body) => {
if (err) return next(err)
req.session.user = body.user
req.session.jwt = body.jwt
res.redirect('/')
})
})// GET /auth/register
router.get('/register', (req, res, next) => {
res.render('auth/register', {title: 'Sign in'})
})// POST /auth/register
router.post('/register', (req, res, next) => {
apiRequest
.post('/auth/local/register', {form: req.body}, (err, response, body) => {
if (err) return next(err)
res.json(body)
})
})// POST /auth/logout
router.post('/logout', (req, res, next) => {
delete req.session.user
delete req.session.jwt
res.redirect('/')
})module.exports = router
``````javascript
// routes/users.js
'use strict'
const express = require('express')
const apiRequest = require('../utils/api')let router = express.Router()
// GET /users
router.get('/', (req, res, next) => {
apiRequest({
uri: `/user`,
qs: {
sort: 'createdAt DESC'
}
}, (err, response, body) => {
if (err) return next(err)
res.render('users/index', {users: body})
})
})// GET /users/:id
router.get('/:id', (req, res, next) => {
apiRequest({
uri: `/user/${req.params.id}`,
qs: {
populate: 'articles'
}
}, (err, response, body) => {
if (err) return next(err)
res.render('users/show', {user: body})
})
})module.exports = router
```