Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
3826b14149
|
64
.gitignore
vendored
64
.gitignore
vendored
@@ -1,64 +1,2 @@
|
||||
# Cache and logs (Symfony2)
|
||||
/app/cache/*
|
||||
/app/logs/*
|
||||
!app/cache/.gitkeep
|
||||
!app/logs/.gitkeep
|
||||
|
||||
# Email spool folder
|
||||
/app/spool/*
|
||||
|
||||
# Cache, session files and logs (Symfony3)
|
||||
/var/cache/*
|
||||
/var/logs/*
|
||||
/var/sessions/*
|
||||
!var/cache/.gitkeep
|
||||
!var/logs/.gitkeep
|
||||
!var/sessions/.gitkeep
|
||||
|
||||
# Logs (Symfony4)
|
||||
/var/log/*
|
||||
!var/log/.gitkeep
|
||||
|
||||
# Parameters
|
||||
/app/config/parameters.yml
|
||||
/app/config/parameters.ini
|
||||
|
||||
# Managed by Composer
|
||||
/app/bootstrap.php.cache
|
||||
/var/bootstrap.php.cache
|
||||
/bin/*
|
||||
!bin/console
|
||||
!bin/symfony_requirements
|
||||
/vendor/
|
||||
|
||||
# Assets and user uploads
|
||||
/web/bundles/
|
||||
/web/uploads/
|
||||
|
||||
# PHPUnit
|
||||
/app/phpunit.xml
|
||||
/phpunit.xml
|
||||
|
||||
# Build data
|
||||
/build/
|
||||
|
||||
# Composer PHAR
|
||||
/composer.phar
|
||||
|
||||
# Backup entities generated with doctrine:generate:entities command
|
||||
**/Entity/*~
|
||||
|
||||
# Embedded web-server pid file
|
||||
/.web-server-pid
|
||||
|
||||
###> symfony/framework-bundle ###
|
||||
/.env.local
|
||||
/.env.local.php
|
||||
/.env.*.local
|
||||
/config/secrets/prod/prod.decrypt.private.php
|
||||
/public/bundles/
|
||||
/var/
|
||||
/vendor/
|
||||
###< symfony/framework-bundle ###
|
||||
|
||||
node_modules
|
||||
.env
|
||||
21
bin/console
21
bin/console
@@ -1,21 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
use App\Kernel;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
|
||||
if (!is_dir(dirname(__DIR__).'/vendor')) {
|
||||
throw new LogicException('Dependencies are missing. Try running "composer install".');
|
||||
}
|
||||
|
||||
if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
|
||||
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
|
||||
}
|
||||
|
||||
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
|
||||
|
||||
return function (array $context) {
|
||||
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
|
||||
|
||||
return new Application($kernel);
|
||||
};
|
||||
@@ -1,68 +0,0 @@
|
||||
{
|
||||
"type": "project",
|
||||
"license": "proprietary",
|
||||
"minimum-stability": "stable",
|
||||
"prefer-stable": true,
|
||||
"require": {
|
||||
"php": ">=8.2",
|
||||
"ext-ctype": "*",
|
||||
"ext-iconv": "*",
|
||||
"symfony/console": "7.1.*",
|
||||
"symfony/dotenv": "7.1.*",
|
||||
"symfony/flex": "^2",
|
||||
"symfony/framework-bundle": "7.1.*",
|
||||
"symfony/runtime": "7.1.*",
|
||||
"symfony/yaml": "7.1.*"
|
||||
},
|
||||
"require-dev": {
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"php-http/discovery": true,
|
||||
"symfony/flex": true,
|
||||
"symfony/runtime": true
|
||||
},
|
||||
"sort-packages": true
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"App\\Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"replace": {
|
||||
"symfony/polyfill-ctype": "*",
|
||||
"symfony/polyfill-iconv": "*",
|
||||
"symfony/polyfill-php72": "*",
|
||||
"symfony/polyfill-php73": "*",
|
||||
"symfony/polyfill-php74": "*",
|
||||
"symfony/polyfill-php80": "*",
|
||||
"symfony/polyfill-php81": "*",
|
||||
"symfony/polyfill-php82": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"auto-scripts": {
|
||||
"cache:clear": "symfony-cmd",
|
||||
"assets:install %PUBLIC_DIR%": "symfony-cmd"
|
||||
},
|
||||
"post-install-cmd": [
|
||||
"@auto-scripts"
|
||||
],
|
||||
"post-update-cmd": [
|
||||
"@auto-scripts"
|
||||
]
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/symfony": "*"
|
||||
},
|
||||
"extra": {
|
||||
"symfony": {
|
||||
"allow-contrib": false,
|
||||
"require": "7.1.*"
|
||||
}
|
||||
}
|
||||
}
|
||||
2430
composer.lock
generated
2430
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
|
||||
];
|
||||
@@ -1,19 +0,0 @@
|
||||
framework:
|
||||
cache:
|
||||
# Unique name of your app: used to compute stable namespaces for cache keys.
|
||||
#prefix_seed: your_vendor_name/app_name
|
||||
|
||||
# The "app" cache stores to the filesystem by default.
|
||||
# The data in this cache should persist between deploys.
|
||||
# Other options include:
|
||||
|
||||
# Redis
|
||||
#app: cache.adapter.redis
|
||||
#default_redis_provider: redis://localhost
|
||||
|
||||
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
|
||||
#app: cache.adapter.apcu
|
||||
|
||||
# Namespaced pools use the above "app" backend by default
|
||||
#pools:
|
||||
#my.dedicated.cache: null
|
||||
@@ -1,16 +0,0 @@
|
||||
# see https://symfony.com/doc/current/reference/configuration/framework.html
|
||||
framework:
|
||||
secret: '%env(APP_SECRET)%'
|
||||
#csrf_protection: true
|
||||
|
||||
# Note that the session will be started ONLY if you read or write from it.
|
||||
session: true
|
||||
|
||||
#esi: true
|
||||
#fragments: true
|
||||
|
||||
when@test:
|
||||
framework:
|
||||
test: true
|
||||
session:
|
||||
storage_factory_id: session.storage.factory.mock_file
|
||||
@@ -1,10 +0,0 @@
|
||||
framework:
|
||||
router:
|
||||
# Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
|
||||
# See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
|
||||
#default_uri: http://localhost
|
||||
|
||||
when@prod:
|
||||
framework:
|
||||
router:
|
||||
strict_requirements: null
|
||||
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) {
|
||||
require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php';
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
controllers:
|
||||
resource:
|
||||
path: ../src/Controller/
|
||||
namespace: App\Controller
|
||||
type: attribute
|
||||
@@ -1,4 +0,0 @@
|
||||
when@dev:
|
||||
_errors:
|
||||
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
|
||||
prefix: /_error
|
||||
@@ -1,24 +0,0 @@
|
||||
# This file is the entry point to configure your own services.
|
||||
# Files in the packages/ subdirectory configure your dependencies.
|
||||
|
||||
# Put parameters here that don't need to change on each machine where the app is deployed
|
||||
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
|
||||
parameters:
|
||||
|
||||
services:
|
||||
# default configuration for services in *this* file
|
||||
_defaults:
|
||||
autowire: true # Automatically injects dependencies in your services.
|
||||
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
|
||||
|
||||
# makes classes in src/ available to be used as services
|
||||
# this creates a service per class whose id is the fully-qualified class name
|
||||
App\:
|
||||
resource: '../src/'
|
||||
exclude:
|
||||
- '../src/DependencyInjection/'
|
||||
- '../src/Entity/'
|
||||
- '../src/Kernel.php'
|
||||
|
||||
# add more service definitions when explicit configuration is needed
|
||||
# please note that last definitions always *replace* previous ones
|
||||
2199
package-lock.json
generated
Normal file
2199
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
35
package.json
Normal file
35
package.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "multiminesweeper-api",
|
||||
"version": "0.1.0",
|
||||
"description": "A backend with Express and SocketIO for my minesweeper game",
|
||||
"author": "Zachary Guénot",
|
||||
"license": "ISC",
|
||||
"main": "index.ts",
|
||||
"scripts": {
|
||||
"start": "ts-node src/index.ts",
|
||||
"dev": "nodemon src/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"dotenv": "^16.4.5",
|
||||
"express": "^4.21.1",
|
||||
"mongoose": "^8.8.0",
|
||||
"socket.io": "^4.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@swc/core": "^1.7.42",
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/node": "^22.8.6",
|
||||
"@types/socket.io": "^3.0.1",
|
||||
"nodemon": "^3.1.7",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.6.3"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Angels-dev/MultiMinesweeper-API.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Angels-dev/MultiMinesweeper-API/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Angels-dev/MultiMinesweeper-API#readme"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Kernel;
|
||||
|
||||
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
|
||||
|
||||
return function (array $context) {
|
||||
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
|
||||
};
|
||||
0
src/Controller/.gitignore
vendored
0
src/Controller/.gitignore
vendored
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
||||
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
|
||||
|
||||
class Kernel extends BaseKernel
|
||||
{
|
||||
use MicroKernelTrait;
|
||||
}
|
||||
44
src/app.ts
Normal file
44
src/app.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { app } from './index'
|
||||
|
||||
app.get ('/api/ping', (req, res) => {
|
||||
res.send('Pong !')
|
||||
})
|
||||
|
||||
/*
|
||||
const mainRouter = express.Router()
|
||||
const wsRouter = express.Router()
|
||||
|
||||
app.use('/', mainRouter)
|
||||
app.use('/ws', wsRouter)
|
||||
|
||||
mainRouter.use(require('cookie-parser')())
|
||||
mainRouter.use(require('body-parser').urlencoded({ extended: false }))
|
||||
mainRouter.use(require('express-dart-sass')({ src: __dirname.split('components')[0], dest: __dirname.split('src/components')[0] + 'public' }))
|
||||
mainRouter.use(express.static('./public'))
|
||||
mainRouter.use(historize)
|
||||
app.set('view engine', 'ejs')
|
||||
app.set('views', './src/views')
|
||||
|
||||
|
||||
// REQUETES GET
|
||||
mainRouter.get('/', async (req, res) => {
|
||||
try {
|
||||
return res.redirect(302, 'index')
|
||||
} catch (err) { console.error(err) }
|
||||
})
|
||||
//
|
||||
mainRouter.get('/index', async (req, res) => {
|
||||
try {
|
||||
req.params.IDInstallation = installCheckID
|
||||
await reqProcess(req)
|
||||
res.render('index', { webPath })
|
||||
} catch (err) {
|
||||
if (err.status === 'error') return res.redirect(302, 'login')
|
||||
}
|
||||
})
|
||||
//
|
||||
mainRouter.get('/login', async (req, res) => {
|
||||
try { res.render('login/index', { webPath }) }
|
||||
catch (err) { console.error(err) }
|
||||
})
|
||||
*/
|
||||
9
src/config/database.ts
Normal file
9
src/config/database.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { connect } from 'mongoose'
|
||||
import 'dotenv/config'
|
||||
|
||||
export const connectDB = async () => {
|
||||
try {
|
||||
const mongo_url = `mongodb://${process.env.MONGOOSE_USER}:${process.env.MONGOOSE_PASSWORD}@${process.env.MONGOOSE_HOST}/${process.env.MONGOOSE_DATABASE}`
|
||||
await connect(mongo_url).catch(console.error)
|
||||
} catch (error) { console.error('Error connecting to MongoDB', error) }
|
||||
}
|
||||
18
src/index.ts
Normal file
18
src/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import express from 'express'
|
||||
import http from 'http'
|
||||
import { Server } from 'socket.io'
|
||||
import { connectDB } from './config/database'
|
||||
import { setupGameSocket } from './sockets/gameSocket'
|
||||
|
||||
const app = express()
|
||||
const server = http.createServer(app)
|
||||
const io = new Server(server)
|
||||
|
||||
// Connexion à MongoDB
|
||||
connectDB()
|
||||
|
||||
// Configuration de Socket.IO
|
||||
setupGameSocket(io)
|
||||
|
||||
// Routes et Middlewares ici
|
||||
export { app, server }
|
||||
8
src/models/User.ts
Normal file
8
src/models/User.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
const userSchema = new mongoose.Schema({
|
||||
username: { type: String, required: true },
|
||||
score: { type: Number, default: 0 }
|
||||
})
|
||||
|
||||
export const User = mongoose.model('User', userSchema)
|
||||
5
src/server.ts
Normal file
5
src/server.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { server } from './index'
|
||||
|
||||
const port = process.env.PORT || 3000
|
||||
|
||||
server.listen(port, () => console.log(`Server running on port ${port}`))
|
||||
16
src/sockets/gameSocket.ts
Normal file
16
src/sockets/gameSocket.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Server, Socket } from 'socket.io'
|
||||
|
||||
export const setupGameSocket = (io: Server) => {
|
||||
io.on('connection', (socket: Socket) => {
|
||||
console.log(`User connected: ${socket.id}`)
|
||||
|
||||
socket.on('move', (data) => {
|
||||
// Gère le mouvement du joueur et envoie les données aux autres clients
|
||||
socket.broadcast.emit('move', data)
|
||||
})
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
console.log(`User disconnected: ${socket.id}`)
|
||||
})
|
||||
})
|
||||
}
|
||||
58
symfony.lock
58
symfony.lock
@@ -1,58 +0,0 @@
|
||||
{
|
||||
"symfony/console": {
|
||||
"version": "7.1",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "5.3",
|
||||
"ref": "1781ff40d8a17d87cf53f8d4cf0c8346ed2bb461"
|
||||
},
|
||||
"files": [
|
||||
"bin/console"
|
||||
]
|
||||
},
|
||||
"symfony/flex": {
|
||||
"version": "2.4",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "1.0",
|
||||
"ref": "146251ae39e06a95be0fe3d13c807bcf3938b172"
|
||||
},
|
||||
"files": [
|
||||
".env"
|
||||
]
|
||||
},
|
||||
"symfony/framework-bundle": {
|
||||
"version": "7.1",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "7.0",
|
||||
"ref": "6356c19b9ae08e7763e4ba2d9ae63043efc75db5"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/cache.yaml",
|
||||
"config/packages/framework.yaml",
|
||||
"config/preload.php",
|
||||
"config/routes/framework.yaml",
|
||||
"config/services.yaml",
|
||||
"public/index.php",
|
||||
"src/Controller/.gitignore",
|
||||
"src/Kernel.php"
|
||||
]
|
||||
},
|
||||
"symfony/routing": {
|
||||
"version": "7.1",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "7.0",
|
||||
"ref": "21b72649d5622d8f7da329ffb5afb232a023619d"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/routing.yaml",
|
||||
"config/routes.yaml"
|
||||
]
|
||||
}
|
||||
}
|
||||
21
tsconfig.json
Normal file
21
tsconfig.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
"module": "CommonJS", /* Specify what module code is generated. */
|
||||
"types": ["node"], /* Specify type package names to be included without being referenced in a source file. */
|
||||
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
||||
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
||||
"checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
|
||||
"resolveJsonModule": true
|
||||
},
|
||||
"include": ["./src/**/*"],
|
||||
|
||||
"ts-node": {
|
||||
"transpileOnly": true,
|
||||
"transpiler": "@swc/core"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user