Parcourir la source

* Added config file
* Added route system
* Added listScenes route

rigwild il y a 5 ans
Parent
commit
dd49f8c64e
6 fichiers modifiés avec 54 ajouts et 15 suppressions
  1. 2 0
      .gitignore
  2. 4 9
      README.md
  3. 8 6
      api/index.js
  4. 10 0
      api/routes/index.js
  5. 17 0
      api/routes/listScenes.js
  6. 13 0
      config.js

+ 2 - 0
.gitignore

@@ -19,3 +19,5 @@ yarn-error.log*
 *.njsproj
 *.sln
 *.sw*
+
+/images

+ 4 - 9
README.md

@@ -1,4 +1,7 @@
-# expe-web
+# Antoine_Internship
+
+Travaux développés par Antoine dans le cadre de son stage de DUT2.
+
 
 ## Project setup
 ```
@@ -15,15 +18,7 @@ yarn run serve
 yarn run build
 ```
 
-### Run your tests
-```
-yarn run test
-```
-
 ### Lints and fixes files
 ```
 yarn run lint
 ```
-
-### Customize configuration
-See [Configuration Reference](https://cli.vuejs.org/config/).

+ 8 - 6
api/index.js

@@ -1,12 +1,14 @@
+'use strict'
+
 import express from 'express'
+import routes from './routes'
+
+import { apiConfig } from '../config'
 
 const app = express()
-const port = 8080
 
-app.listen(port, () => {
-  console.log('The server was started on http://localhost:' + port)
+app.listen(apiConfig.port, () => {
+  console.log('The server was started on http://localhost:' + apiConfig.port)
 })
 
-app.get('/', (req, res) => {
-  res.send('it works')
-})
+app.use(apiConfig.routePrefix, routes)

+ 10 - 0
api/routes/index.js

@@ -0,0 +1,10 @@
+'use strict'
+
+import express from 'express'
+import listScenes from './listScenes'
+
+const router = express.Router()
+
+router.use('/listScenes', listScenes)
+
+export default router

+ 17 - 0
api/routes/listScenes.js

@@ -0,0 +1,17 @@
+'use strict'
+
+import express from 'express'
+import { promises } from 'fs'
+
+import { apiConfig } from '../../config'
+
+const fs = promises
+
+const router = express.Router()
+
+router.get('/', async (req, res) => {
+  const dirContent = await fs.readdir(apiConfig.imagesPath)
+  res.json(dirContent)
+})
+
+export default router

+ 13 - 0
config.js

@@ -0,0 +1,13 @@
+'use strict'
+
+import path from 'path'
+
+const PRODUCTION_MODE = process.env.NODE_ENV === 'production'
+
+const apiConfig = {
+  routePrefix: '/api',
+  port: PRODUCTION_MODE ? 80 : 8080,
+  imagesPath: path.resolve(__dirname, 'images')
+}
+
+export { PRODUCTION_MODE, apiConfig }